結果

問題 No.1370 置換門松列
ユーザー ygd.ygd.
提出日時 2021-01-29 22:56:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 917 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 112,332 KB
最終ジャッジ日時 2024-04-25 17:05:28
合計ジャッジ時間 3,860 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,264 KB
testcase_01 AC 36 ms
52,804 KB
testcase_02 AC 36 ms
52,220 KB
testcase_03 AC 37 ms
52,696 KB
testcase_04 AC 37 ms
52,868 KB
testcase_05 AC 37 ms
53,364 KB
testcase_06 AC 37 ms
52,328 KB
testcase_07 AC 36 ms
52,876 KB
testcase_08 AC 37 ms
53,188 KB
testcase_09 AC 37 ms
52,760 KB
testcase_10 AC 38 ms
52,684 KB
testcase_11 AC 37 ms
52,588 KB
testcase_12 AC 37 ms
52,800 KB
testcase_13 AC 38 ms
53,504 KB
testcase_14 AC 37 ms
53,016 KB
testcase_15 AC 37 ms
53,232 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 37 ms
53,384 KB
testcase_19 AC 37 ms
53,080 KB
testcase_20 WA -
testcase_21 AC 141 ms
111,240 KB
testcase_22 RE -
testcase_23 AC 143 ms
112,332 KB
testcase_24 AC 64 ms
87,076 KB
testcase_25 AC 176 ms
111,500 KB
testcase_26 AC 177 ms
111,368 KB
testcase_27 AC 113 ms
108,660 KB
testcase_28 AC 114 ms
108,396 KB
testcase_29 AC 69 ms
86,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
A = list(map(int,input().split()))
ALL = [i for i in range(M)]
ALL = set(ALL)
G = [[] for _ in range(M)]
for i in range(N-1):
    a = A[i] - 1 #0index
    b = A[i+1] - 1
    if a == b:
        print("No");exit()
    if i < N-2:
        c = A[i+2] - 1
        if a == c:
            print("No");exit()
    if i%2 == 0:
        G[a].append(b)
        ALL.discard(b)
    else:
        G[b].append(a)
        ALL.discard(a)
#print(G)

ALL = list(ALL)
used = set([])
TS = []
def dfs(v):
  if v in used:
    return
  used.add(v)
  for w in G[v]:
    if w in used:
      continue
    dfs(w)
    TS.append(w) #帰りがけで記録
for root in ALL: #すべての始点について
  dfs(root)
  TS.append(root)
TS.reverse() #最後に反転
#print(TS)

if len(TS) < M:
    print("No")
else:
    ans = [-1]*M
    for i, v in enumerate(TS):
        ans[v] = i + 1
    print("Yes")
    print(*ans)
0