Approach
Sorting and greedy selection
For ABC213 C — Reorder Cards, 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
- 43 lines of Python from the credited upstream file abc213_c.py.
- The implementation visibly relies on sequence storage, hash lookup, 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 compress_coordinate(elements: list) -> dict:5 ''' Means that reduce the numerical value while maintaining the magnitude6 relationship.7 Args:8 elements: list of integer numbers (greater than -1).9 Returns:10 A dictionary's items ((original number, compressed number) pairs).11 Landau notation: O(n log n)12 '''13 14 15 16 compressed_list = sorted(set(elements))17 return {element: index for index, element in enumerate(compressed_list)}18 19 20def main():21 import sys22 23 input = sys.stdin.readline24 25 h, w, n = map(int, input().split())26 a = list()27 b = list()28 29 for i in range(n):30 ai, bi = map(int, input().split())31 a.append(ai)32 b.append(bi)33 34 ca = compress_coordinate(a)35 cb = compress_coordinate(b)36 37 for ai, bi in zip(a, b):38 print(ca[ai] + 1, cb[bi] + 1)39 40 41if __name__ == "__main__":42 main()43