結果

問題 No.1370 置換門松列
ユーザー convexineq
提出日時 2021-01-30 09:37:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 98,892 KB
最終ジャッジ日時 2024-09-14 19:24:09
合計ジャッジ時間 3,576 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
*a, = map(int,input().split())

for i in range(n-1):
    if a[i] == a[i+1]:
        print("No")
        exit()
for i in range(n-2):
    if a[i] == a[i+2]:
        print("No")
        exit()

g = [[] for _ in range(m+1)]
ind = [0]*(m+1)
for i in range(n-1):
    if i%2:
        g[a[i]].append(a[i+1])
        ind[a[i+1]] += 1
    else:
        g[a[i+1]].append(a[i])
        ind[a[i]] += 1
        
q = [i for i in range(m+1) if i and ind[i]==0]
ans = [0]*m
i = 1
while q:
    v = q.pop()
    ans[v-1] = i
    i += 1
    for c in g[v]:
        ind[c] -= 1
        if ind[c]==0:
            q.append(c)

if any(x for x in ind): print("No")
else:
    print("Yes")
    print(*ans)
0