結果

問題 No.1370 置換門松列
ユーザー convexineqconvexineq
提出日時 2021-01-30 09:37:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 97,584 KB
最終ジャッジ日時 2023-10-12 21:05:07
合計ジャッジ時間 4,879 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,172 KB
testcase_01 AC 72 ms
71,412 KB
testcase_02 AC 72 ms
71,292 KB
testcase_03 AC 72 ms
71,140 KB
testcase_04 AC 70 ms
71,412 KB
testcase_05 AC 71 ms
70,900 KB
testcase_06 AC 72 ms
71,224 KB
testcase_07 AC 71 ms
71,324 KB
testcase_08 AC 73 ms
70,988 KB
testcase_09 AC 71 ms
71,320 KB
testcase_10 AC 72 ms
71,060 KB
testcase_11 AC 72 ms
71,172 KB
testcase_12 AC 73 ms
71,320 KB
testcase_13 AC 71 ms
71,084 KB
testcase_14 AC 72 ms
71,396 KB
testcase_15 AC 72 ms
71,144 KB
testcase_16 AC 73 ms
71,176 KB
testcase_17 AC 71 ms
71,108 KB
testcase_18 AC 72 ms
70,888 KB
testcase_19 AC 72 ms
71,152 KB
testcase_20 AC 72 ms
70,992 KB
testcase_21 AC 151 ms
97,508 KB
testcase_22 AC 120 ms
97,396 KB
testcase_23 AC 151 ms
97,200 KB
testcase_24 AC 103 ms
92,012 KB
testcase_25 AC 173 ms
97,584 KB
testcase_26 AC 172 ms
97,548 KB
testcase_27 AC 122 ms
97,196 KB
testcase_28 AC 123 ms
97,160 KB
testcase_29 AC 108 ms
92,676 KB
権限があれば一括ダウンロードができます

ソースコード

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