結果
| 問題 |
No.1370 置換門松列
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2021-01-29 22:03:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,220 bytes |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 82,312 KB |
| 実行使用メモリ | 96,528 KB |
| 最終ジャッジ日時 | 2024-11-08 04:16:26 |
| 合計ジャッジ時間 | 3,936 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 22 WA * 3 |
ソースコード
"""
大小大小大
M頂点のグラフを考える
><><><
みたいな感じで割り当てる
後はトポロジカルソート
"""
from sys import stdin
import sys
from collections import deque
def kd(L):
if L[0]==L[1] or L[1]==L[2] or L[2]==L[0]:
return False
elif max(L) == L[1] or min(L) == L[1]:
return True
else:
return False
def kdl(L):
for i in range(len(L)-2):
if not kd(L[i:i+3]):
return False
return True
N,M = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))
if M < 3:
print ("No")
sys.exit()
lis = [ [] for i in range(M)]
Inum = [0] * M
for i in range(N-1):
if i % 2 == 0:
v,u = a[i]-1,a[i+1]-1
else:
u,v = a[i]-1,a[i+1]-1
if u == v:
print ("No")
sys.exit()
lis[v].append(u)
Inum[u] += 1
use = 1
d = [1] * M
q = deque([])
for i in range(M):
if Inum[i] == 0:
q.append(i)
end = 0
while q:
v = q.popleft()
d[v] = use
use += 1
end += 1
for nex in lis[v]:
Inum[nex] -= 1
if Inum[nex] == 0:
q.append(nex)
if end != M:
print ("No")
else:
print ("Yes")
print (*d)
SPD_9X2