Approach
Sorting and greedy selection
For ABC324 C — Error Correction, 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
- 68 lines of Python from the credited upstream file abc324_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 main():5 import sys6 7 input = sys.stdin.readline8 9 n, t_dash = input().rstrip().split()10 m = len(t_dash)11 n = int(n)12 ans = list()13 14 for i in range(1, n + 1):15 si = input().rstrip()16 u = len(si)17 18 if abs(u - m) > 2:19 continue20 21 if u == m:22 count = 023 24 for ti, sij in zip(t_dash, si):25 if ti != sij:26 count += 127 28 if count <= 1:29 ans.append(i)30 else:31 if m > u:32 pos = 033 34 for x, (ti, sij) in enumerate(zip(t_dash, si)):35 if ti != sij:36 pos = x37 break38 39 if t_dash[pos + 1 :] == si[pos:]:40 ans.append(i)41 elif t_dash[1:] == si:42 ans.append(i)43 elif t_dash[:-1] == si:44 ans.append(i)45 else:46 pos = 047 48 for x, (ti, sij) in enumerate(zip(t_dash, si)):49 if ti != sij:50 pos = x51 break52 53 if t_dash[pos:] == si[pos + 1 :]:54 ans.append(i)55 elif t_dash == si[1:]:56 ans.append(i)57 elif t_dash == si[:-1]:58 ans.append(i)59 60 print(len(set(ans)))61 62 if len(ans) > 0:63 print(*sorted(set(ans)))64 65 66if __name__ == "__main__":67 main()68