結果
| 問題 |
No.2740 Old Maid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-21 11:34:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 775 bytes |
| コンパイル時間 | 261 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 128,096 KB |
| 最終ジャッジ日時 | 2024-10-13 10:09:39 |
| 合計ジャッジ時間 | 8,881 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 53 |
ソースコード
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]*N
for i in range(N):
where[p[i]-1] = i
visited = [-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]
visited[i] = 1
visited[next_node-1] = 1
ans.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)