結果
問題 | No.2740 Old Maid |
ユーザー |
|
提出日時 | 2024-04-21 11:37:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 826 bytes |
コンパイル時間 | 886 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 120,448 KB |
最終ジャッジ日時 | 2024-10-13 10:11:26 |
合計ジャッジ時間 | 10,323 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 62 |
ソースコード
N = int(input())p = list(map(int, input().split()))_next = [-1]*(N+1)before = [-1]*(N+1)for i in range(N-1):_next[p[i]] = p[i+1]before[p[i+1]] = p[i]where = [-1]*Nfor i in range(N):where[p[i]-1] = ivisited = [-1]*N#print(_next)#print(where)#print(before)ans = []for i in range(N):if visited[i] == 1 or where[i] == N-1:continue#print(i)next_node = _next[i+1]if visited[next_node-1] == 1:continuevisited[i] = 1visited[next_node-1] = 1ans.append(i+1)ans.append(next_node)if before[i+1] != -1 and _next[next_node] != -1:#print(i)_next[before[i+1]] = _next[next_node]before[_next[next_node]] = before[i+1]before[i+1],_next[i+1],before[next_node],_next[next_node] = -1,-1,-1,-1#print(visited)print(*ans)