結果

問題 No.2740 Old Maid
ユーザー N_noa21N_noa21
提出日時 2024-04-21 11:37:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 120,496 KB
最終ジャッジ日時 2024-04-21 11:38:03
合計ジャッジ時間 10,009 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
112,256 KB
testcase_01 AC 153 ms
112,640 KB
testcase_02 AC 154 ms
112,384 KB
testcase_03 AC 153 ms
112,512 KB
testcase_04 AC 179 ms
112,384 KB
testcase_05 AC 150 ms
112,512 KB
testcase_06 AC 149 ms
112,384 KB
testcase_07 AC 157 ms
112,512 KB
testcase_08 AC 150 ms
112,128 KB
testcase_09 AC 152 ms
112,768 KB
testcase_10 AC 148 ms
112,384 KB
testcase_11 AC 151 ms
112,256 KB
testcase_12 AC 133 ms
112,128 KB
testcase_13 AC 136 ms
116,736 KB
testcase_14 AC 84 ms
82,816 KB
testcase_15 AC 87 ms
85,760 KB
testcase_16 AC 119 ms
106,496 KB
testcase_17 AC 83 ms
81,792 KB
testcase_18 AC 136 ms
112,512 KB
testcase_19 AC 96 ms
91,008 KB
testcase_20 AC 143 ms
119,296 KB
testcase_21 AC 84 ms
84,352 KB
testcase_22 AC 118 ms
106,112 KB
testcase_23 AC 73 ms
77,184 KB
testcase_24 AC 93 ms
91,008 KB
testcase_25 AC 150 ms
108,416 KB
testcase_26 AC 62 ms
66,560 KB
testcase_27 AC 72 ms
73,856 KB
testcase_28 AC 142 ms
106,368 KB
testcase_29 AC 138 ms
103,424 KB
testcase_30 AC 68 ms
68,096 KB
testcase_31 AC 157 ms
112,256 KB
testcase_32 AC 99 ms
93,568 KB
testcase_33 AC 152 ms
108,288 KB
testcase_34 AC 133 ms
103,168 KB
testcase_35 AC 110 ms
89,856 KB
testcase_36 AC 96 ms
91,392 KB
testcase_37 AC 102 ms
98,688 KB
testcase_38 AC 92 ms
88,984 KB
testcase_39 AC 81 ms
81,268 KB
testcase_40 AC 127 ms
110,720 KB
testcase_41 AC 147 ms
120,496 KB
testcase_42 AC 40 ms
51,968 KB
testcase_43 AC 40 ms
51,968 KB
testcase_44 AC 40 ms
51,968 KB
testcase_45 AC 39 ms
51,584 KB
testcase_46 AC 39 ms
51,840 KB
testcase_47 AC 48 ms
52,224 KB
testcase_48 AC 40 ms
51,968 KB
testcase_49 AC 41 ms
51,968 KB
testcase_50 AC 40 ms
51,968 KB
testcase_51 AC 39 ms
52,224 KB
testcase_52 AC 39 ms
51,968 KB
testcase_53 AC 40 ms
52,096 KB
testcase_54 AC 41 ms
51,584 KB
testcase_55 AC 39 ms
52,224 KB
testcase_56 AC 39 ms
52,096 KB
testcase_57 AC 38 ms
51,968 KB
testcase_58 AC 40 ms
52,096 KB
testcase_59 AC 40 ms
51,840 KB
testcase_60 AC 40 ms
51,968 KB
testcase_61 AC 40 ms
52,224 KB
testcase_62 AC 39 ms
51,968 KB
testcase_63 AC 40 ms
52,224 KB
testcase_64 AC 39 ms
51,968 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]
    if visited[next_node-1] == 1:
        continue
    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