Approach
Sorting and greedy selection
For ABC222 C — Swiss-System Tournament, the implementation first exposes a useful order, then scans that order while making locally justified choices.
- Choose the key that reveals the greedy or grouping structure.
- Sort the relevant records by that key.
- Scan in order, maintaining the invariant that makes each local choice safe.
Code notes
- 53 lines of Python from the credited upstream file abc222_c.py.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Sorting is typically the dominant term unless the subsequent scan uses a more expensive nested operation.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def judge(first_hand, second_hand):5 6 7 8 9 if first_hand == second_hand:10 return -111 elif first_hand == 'G' and second_hand == 'C':12 return 013 elif first_hand == 'C' and second_hand == 'P':14 return 015 elif first_hand == 'P' and second_hand == 'G':16 return 017 18 return 119 20 21def main():22 n, m = map(int, input().split())23 a = [list(input()) for _ in range(2 * n)]24 win_count = [0] * (2 * n)25 26 for j in range(m):27 order = [(count, index) for index, count in enumerate(win_count)]28 sorted_order = sorted(order, key=lambda x: (x[0], -x[1]) ,reverse=True)29 30 for i in range(n):31 first_id = sorted_order[2 * i][1]32 first_hand = a[first_id][j]33 34 second_id = sorted_order[2 * i + 1][1]35 second_hand = a[second_id][j]36 37 result = judge(first_hand, second_hand)38 39 if result == 0:40 win_count[first_id] += 141 elif result == 1:42 win_count[second_id] += 143 44 order = [(count, index) for index, count in enumerate(win_count)]45 sorted_order = sorted(order, key=lambda x: (x[0], -x[1]) ,reverse=True)46 47 for _, index in sorted_order:48 print(index + 1)49 50 51if __name__ == "__main__":52 main()53