結果
問題 | No.1370 置換門松列 |
ユーザー |
![]() |
提出日時 | 2021-01-30 13:26:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 1,171 bytes |
コンパイル時間 | 315 ms |
コンパイル使用メモリ | 82,400 KB |
実行使用メモリ | 116,864 KB |
最終ジャッジ日時 | 2024-09-14 19:24:18 |
合計ジャッジ時間 | 4,012 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 25 |
ソースコード
#1370import sys;input = lambda: sys.stdin.readline().rstrip()#import numpy as np#import heapqfrom collections import dequedef 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 Falsereturn 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]*mfor i in range(m):X[ts[i]] = i+1print(*X, sep = ' ')