結果

問題 No.1370 置換門松列
ユーザー ygd.ygd.
提出日時 2021-01-30 00:08:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 86,676 KB
実行使用メモリ 111,044 KB
最終ジャッジ日時 2023-10-12 21:04:42
合計ジャッジ時間 5,518 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,724 KB
testcase_01 AC 94 ms
71,416 KB
testcase_02 AC 92 ms
71,388 KB
testcase_03 AC 91 ms
71,480 KB
testcase_04 AC 91 ms
71,432 KB
testcase_05 AC 93 ms
71,428 KB
testcase_06 AC 93 ms
71,508 KB
testcase_07 AC 92 ms
71,520 KB
testcase_08 AC 97 ms
71,588 KB
testcase_09 AC 93 ms
71,476 KB
testcase_10 AC 92 ms
71,428 KB
testcase_11 AC 92 ms
71,588 KB
testcase_12 AC 92 ms
71,356 KB
testcase_13 AC 92 ms
71,604 KB
testcase_14 AC 96 ms
71,524 KB
testcase_15 AC 94 ms
71,480 KB
testcase_16 AC 94 ms
71,500 KB
testcase_17 AC 92 ms
71,492 KB
testcase_18 AC 95 ms
71,508 KB
testcase_19 AC 95 ms
71,652 KB
testcase_20 AC 92 ms
71,524 KB
testcase_21 AC 168 ms
105,008 KB
testcase_22 AC 139 ms
103,968 KB
testcase_23 AC 174 ms
111,044 KB
testcase_24 AC 120 ms
92,120 KB
testcase_25 AC 197 ms
103,592 KB
testcase_26 AC 201 ms
103,784 KB
testcase_27 AC 145 ms
106,864 KB
testcase_28 AC 144 ms
106,548 KB
testcase_29 AC 125 ms
90,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N,M = map(int,input().split()); INF = float("inf")
A = list(map(int,input().split()))
G = [[] for _ in range(M)]
deg1 = [0] * M #出次数
deg2 = [0] * 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)
        deg1[a] += 1
        deg2[b] += 1
    else:
        G[b].append(a)
        deg1[b] += 1
        deg2[a] += 1
#print(G)

def topological(start,graph):
    topo = []
    while start:
        v = start.pop()
        topo.append(v)
        for u in graph[v]:
            deg2[u] -= 1
            if deg2[u] == 0:
                start.append(u)
    # print(edges, minscore)
 
    return topo

SG = []
used = [0] * M
start = []
for i in range(M):
    if deg2[i] == 0:
        SG.append(i)
#print(SG)
TS = topological(SG,G)
#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