thảo luận Leetcode + Codeforces, Competitive programming contest. Đường tới Guardian + Candidate Master.

  • Người tạo chủ đề Người tạo chủ đề freedom.9
  • Ngày bắt đầu Ngày bắt đầu
Q2 greedy đủ tư thế, nào là dùng stack, nào là sort theo freq :v nhưng thế éo nào em vẫn tạch. Soi ra thì thấy quả công thức quỷ @@
 
Q2 greedy đủ tư thế, nào là dùng stack, nào là sort theo freq :v nhưng thế éo nào em vẫn tạch. Soi ra thì thấy quả công thức quỷ @@
Thực ra dùng heap đc đó fen, tính pairs cho group left, pairs cho group right, xử lí cái case special remaining thôi là ăn
zFNuZTA.gif



via theNEXTvoz for iPhone
 
Kinh nghiệm làm contest đầy mình :doubt: đá qua 4 câu thấy câu 3 intuitive múc luôn. Câu 2 ngồi loay hoay mãi ko ra vẫn rank 1k2 :ah: bỏ cheaters chắc còn < 1k vẫn + delta như thường
Q4 chắc dân CF mới làm nổi, toàn math là math mệt vãi ko nhìn ra ý tưởng là đúng rồi
Q2 thì éo biết cái cách tính pairs greedy cho nó đúng, tạch ko oan =((
Đáng ra lúc thấy Q2 rate thấp em quay qua Q3 luôn thì bú, quần mãi Q2 hơn 30 phút
Thực ra dùng heap đc đó fen, tính pairs cho group left, pairs cho group right, xử lí cái case special remaining thôi là ăn
zFNuZTA.gif



via theNEXTvoz for iPhone
Vẫn là DNA issue 🥹 🥹 🥹
 
Mới code lại bài 2 xài heap cho dễ hiểu.

Python:
class Solution:
    def score(self, cards: List[str], x: str) -> int:
        group1 = defaultdict(int)
        group2 = defaultdict(int)
        specials = 0
        for card in cards:
            if card[0] == x and card[1] == x:
                specials += 1
                continue

            if card[0] == x:
                group1[card] += 1

            if card[1] == x:
                group2[card] += 1

        def count(group):
            heap = []
            for key, val in group.items():
                heapq.heappush(heap, -val)

            total = 0
            while len(heap) > 1:
                a = -heapq.heappop(heap)
                b = -heapq.heappop(heap)
                total += 1
                if a - 1 > 0:
                    heapq.heappush(heap, 1 - a)
                
                if b - 1> 0:
                    heapq.heappush(heap, 1 - b)

            reamaining = 0
            while heap:
                reamaining += -heapq.heappop(heap)

            return total, reamaining

        # Good pairs from left group + remaining items which is not yet paired
        left, leftRemaining = count(group1)

        # Good pairs from right group + remaining items which is not yet paired
        right, rightRemaining = count(group2)

        total = left + right

        # Use specials to pair with all left + right remaining.
        total += min(specials, leftRemaining)
        specials -= min(specials, leftRemaining)

        total += min(specials, rightRemaining)
        specials -= min(specials, rightRemaining)

        # If any special items remaining, we can break the good pairs by specials to get more pairs
        total += min(left + right, specials//2)
        return total
 
Má nó quả này trừ 100 điểm là có thật, lậm bài 3 dùng trie quá sai mẹ test case rồi, gục luôn q2 =((
 
Má nó biết ngay bài 3 có thể dùng trie mà, con mẹ nó recursion là ngon rồi éo code ra huhu cay quá
 
g3wDD5m.png
top 2 giải 4q trong 6 phút. nó làm bài med với hard chắc cũng tương đương mình làm mấy câu ez nhỉ. e làm q1 cũng hết 4-5 p cmnr
uC4QdFi.png
 

Thống kê chủ đề

Ngày tạo
freedom.9,
Người trả lời cuối
deple20k,
Trả lời
1.686
Lượt xem
107.173
Quay lại
Lên đầu trang