結果

問題 No.1370 置換門松列
ユーザー ygd.ygd.
提出日時 2021-01-29 23:41:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,163 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 101,416 KB
最終ジャッジ日時 2024-04-25 17:05:59
合計ジャッジ時間 3,735 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,816 KB
testcase_01 AC 42 ms
55,140 KB
testcase_02 AC 40 ms
55,096 KB
testcase_03 AC 42 ms
54,440 KB
testcase_04 AC 41 ms
54,520 KB
testcase_05 AC 43 ms
55,604 KB
testcase_06 AC 41 ms
54,740 KB
testcase_07 AC 41 ms
55,596 KB
testcase_08 WA -
testcase_09 AC 42 ms
54,540 KB
testcase_10 WA -
testcase_11 AC 42 ms
53,792 KB
testcase_12 AC 41 ms
55,152 KB
testcase_13 AC 41 ms
53,960 KB
testcase_14 AC 41 ms
54,552 KB
testcase_15 WA -
testcase_16 AC 41 ms
54,508 KB
testcase_17 AC 41 ms
55,156 KB
testcase_18 AC 41 ms
54,560 KB
testcase_19 AC 41 ms
55,924 KB
testcase_20 AC 41 ms
54,924 KB
testcase_21 AC 132 ms
101,224 KB
testcase_22 AC 87 ms
97,060 KB
testcase_23 WA -
testcase_24 AC 69 ms
88,688 KB
testcase_25 AC 156 ms
101,204 KB
testcase_26 AC 156 ms
101,416 KB
testcase_27 AC 85 ms
95,352 KB
testcase_28 AC 87 ms
95,784 KB
testcase_29 AC 71 ms
87,840 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[b] += 1
        deg2[a] += 1
    else:
        G[b].append(a)
        deg1[a] += 1
        deg2[b] += 1
#print(G)

def topological(start,graph):
    topo = []
    start1 = deque(start)
    res = -INF
    while start1:
        v = start1.popleft()
        topo.append(v)
        for u in graph[v]:
            deg1[u] -= 1
            if deg1[u] == 0:
                start1.append(u)
    # print(edges, minscore)
 
    return topo

SG = []
used = [0] * M
start = []
for i in range(M):
    if deg1[i] == 0 and deg2[i] > 0:
        SG.append(i)
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