結果

問題 No.1370 置換門松列
ユーザー GER_chenGER_chen
提出日時 2021-01-30 13:23:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 120,140 KB
最終ジャッジ日時 2024-04-25 17:06:17
合計ジャッジ時間 4,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,908 KB
testcase_01 AC 40 ms
54,912 KB
testcase_02 AC 41 ms
53,980 KB
testcase_03 AC 42 ms
54,840 KB
testcase_04 WA -
testcase_05 AC 41 ms
53,860 KB
testcase_06 WA -
testcase_07 AC 42 ms
55,464 KB
testcase_08 AC 41 ms
54,132 KB
testcase_09 AC 43 ms
55,252 KB
testcase_10 AC 44 ms
55,056 KB
testcase_11 AC 41 ms
55,440 KB
testcase_12 AC 42 ms
54,044 KB
testcase_13 AC 41 ms
54,132 KB
testcase_14 AC 41 ms
55,124 KB
testcase_15 AC 42 ms
55,584 KB
testcase_16 AC 41 ms
54,104 KB
testcase_17 AC 41 ms
54,520 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 42 ms
55,236 KB
testcase_21 AC 172 ms
119,876 KB
testcase_22 AC 106 ms
97,520 KB
testcase_23 AC 141 ms
97,552 KB
testcase_24 AC 67 ms
81,548 KB
testcase_25 AC 272 ms
120,140 KB
testcase_26 AC 263 ms
117,572 KB
testcase_27 AC 110 ms
97,380 KB
testcase_28 AC 114 ms
97,680 KB
testcase_29 AC 88 ms
90,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#1370
import sys;input = lambda: sys.stdin.readline().rstrip()
#import numpy as np
#import heapq
from collections import deque
def topological_sort(In, Out):
    """
    In: 入力してくる頂点集合
    Out: 出力先の頂点集合
    """
    dq = deque()
    L = []
    for i, I in enumerate(In):
        if not I:
            dq.append(i)
    while dq:
        v = dq.popleft()
        L.append(v)
        for w in Out[v]:
            In[w].remove(v)
            if not In[w]:
                dq.append(w)
    if len(L) < len(In):
        return False
    return L

# = input()
# = int(input())
n, m = map(int,input().split())
A = list(map(lambda x: int(x)-1,input().split()))  #長さn
#DAGか?
In, Out = [set() for _ in range(m)], [set() for _ in range(m)]
for i in range(n-1):
    if i&1:
        In[A[i]].add(A[i+1])
        Out[A[i+1]].add(A[i])
    else:
        In[A[i+1]].add(A[i])
        Out[A[i]].add(A[i+1])

ts = topological_sort(In, Out)

if not ts:
    print('No')
else:
    print('Yes')
    X = [None]*m
    for i in range(m):
        X[ts[i]] = i+1
    print(*X)
0