結果

問題 No.2740 Old Maid
ユーザー N_noa21N_noa21
提出日時 2024-04-21 11:34:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 128,552 KB
最終ジャッジ日時 2024-04-21 11:34:55
合計ジャッジ時間 9,736 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 144 ms
112,256 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 92 ms
90,752 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 86 ms
88,832 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 42 ms
51,840 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 39 ms
51,840 KB
testcase_50 WA -
testcase_51 AC 37 ms
52,224 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 37 ms
51,584 KB
testcase_56 AC 36 ms
51,968 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 37 ms
51,840 KB
testcase_61 WA -
testcase_62 AC 37 ms
51,840 KB
testcase_63 AC 37 ms
51,712 KB
testcase_64 AC 37 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0