結果

問題 No.1370 置換門松列
ユーザー GER_chenGER_chen
提出日時 2021-01-30 13:26:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 1,171 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 121,548 KB
最終ジャッジ日時 2023-10-12 21:05:19
合計ジャッジ時間 5,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,412 KB
testcase_01 AC 93 ms
71,212 KB
testcase_02 AC 93 ms
71,552 KB
testcase_03 AC 92 ms
71,316 KB
testcase_04 AC 93 ms
71,336 KB
testcase_05 AC 94 ms
71,420 KB
testcase_06 AC 92 ms
71,168 KB
testcase_07 AC 95 ms
71,396 KB
testcase_08 AC 94 ms
71,216 KB
testcase_09 AC 93 ms
71,508 KB
testcase_10 AC 93 ms
71,216 KB
testcase_11 AC 94 ms
71,452 KB
testcase_12 AC 94 ms
71,560 KB
testcase_13 AC 91 ms
71,416 KB
testcase_14 AC 93 ms
71,428 KB
testcase_15 AC 92 ms
71,224 KB
testcase_16 AC 92 ms
71,508 KB
testcase_17 AC 91 ms
71,484 KB
testcase_18 AC 91 ms
71,448 KB
testcase_19 AC 94 ms
71,504 KB
testcase_20 AC 94 ms
71,396 KB
testcase_21 AC 227 ms
121,548 KB
testcase_22 AC 162 ms
92,620 KB
testcase_23 AC 196 ms
97,232 KB
testcase_24 AC 129 ms
92,516 KB
testcase_25 AC 306 ms
118,924 KB
testcase_26 AC 306 ms
118,312 KB
testcase_27 AC 167 ms
94,076 KB
testcase_28 AC 172 ms
94,168 KB
testcase_29 AC 147 ms
90,312 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()))

for i in range(n-2):
    if len(set(A[i:i+3])) != 3:
        print('No')
        exit()

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, sep = ' ')
0