結果

問題 No.1370 置換門松列
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-01-29 21:57:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,165 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 96,872 KB
最終ジャッジ日時 2024-04-25 17:04:28
合計ジャッジ時間 4,174 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,832 KB
testcase_01 AC 37 ms
55,436 KB
testcase_02 AC 39 ms
54,428 KB
testcase_03 WA -
testcase_04 AC 39 ms
55,364 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 38 ms
54,804 KB
testcase_10 WA -
testcase_11 AC 37 ms
55,584 KB
testcase_12 AC 38 ms
54,636 KB
testcase_13 AC 37 ms
55,000 KB
testcase_14 AC 38 ms
55,064 KB
testcase_15 WA -
testcase_16 AC 38 ms
54,600 KB
testcase_17 AC 37 ms
55,992 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 38 ms
54,676 KB
testcase_21 WA -
testcase_22 AC 88 ms
95,848 KB
testcase_23 WA -
testcase_24 AC 62 ms
88,248 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 83 ms
94,228 KB
testcase_28 AC 84 ms
94,168 KB
testcase_29 AC 64 ms
87,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

大小大小大

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

    lis[v].append(u)
    Inum[u] += 1

q = deque([])
for i in range(M):
    if Inum[i] == 0:
        q.append(i)

d = [1] * M
end = 0

while q:

    v = q.popleft()
    end += 1

    for nex in lis[v]:
        d[nex] = max(d[nex] , d[v]+1)
        Inum[nex] -= 1

        if Inum[nex] == 0:
            q.append(nex)

if end != M:
    print ("No")
else:
    print ("Yes")
    print (*d)
0