aNotHeRNo0b
Senior Member
Bài 3 nghĩ phức tạp quá. Bài 4 thì DP + Prefixsum code bị lỏ
Thôi nay sủi, lag như hôm qua nữa lại mệt.


Sống đủ lâu để thấy trang này của Leetcode có tồn tại. Vẫn đang còn để 2025 luôn mà
Xem tệp đính kèm 3413888
Dev cho thêm 1h nữa kìa broSống đủ lâu để thấy trang này của Leetcode có tồn tại. Vẫn đang còn để 2025 luôn mà
Xem tệp đính kèm 3413888
khóc thét ở Q3Hôm nay ranking là của các bác China luôn mà. Hình như có Leetcode US lỗi th, LeetCode CN vẫn mượt.
DNA issue rồi báckhóc thét ở Q3DNA issue rồi bác


Em mới làm thử Q3, greedy dựa vào các case theo thứ tự saukhóc thét ở Q3DNA issue rồi bác
class Solution:
def minimumCost(self, s: str, t: str, flipCost: int, swapCost: int, crossCost: int) -> int:
diff_one, diff_zero = 0, 0
for a, b in zip(s, t):
if a != b:
if a == "1":
diff_one += 1
else:
diff_zero += 1
# print(diff_one, diff_zero)
if flipCost * 2 <= swapCost:
return (diff_one + diff_zero) * flipCost
res = 0
res += min(diff_one, diff_zero) * swapCost
left = max(diff_one, diff_zero) - min(diff_one, diff_zero)
if flipCost * 2 <= swapCost + crossCost:
res += left * flipCost
else:
if left % 2:
res += flipCost
left -= 1
res += (swapCost + crossCost) * left // 2
return res