結果

問題 No.1370 置換門松列
ユーザー titiatitia
提出日時 2021-01-30 03:51:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 10,680 KB
実行使用メモリ 39,860 KB
最終ジャッジ日時 2023-10-12 21:05:01
合計ジャッジ時間 4,947 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,668 KB
testcase_01 AC 16 ms
8,296 KB
testcase_02 AC 19 ms
8,700 KB
testcase_03 AC 19 ms
8,700 KB
testcase_04 AC 16 ms
8,296 KB
testcase_05 AC 19 ms
8,492 KB
testcase_06 AC 17 ms
8,308 KB
testcase_07 AC 18 ms
8,632 KB
testcase_08 AC 19 ms
8,572 KB
testcase_09 AC 19 ms
8,656 KB
testcase_10 AC 19 ms
8,672 KB
testcase_11 AC 16 ms
8,288 KB
testcase_12 AC 16 ms
8,304 KB
testcase_13 AC 19 ms
8,588 KB
testcase_14 AC 19 ms
8,548 KB
testcase_15 AC 19 ms
8,632 KB
testcase_16 AC 19 ms
8,680 KB
testcase_17 AC 19 ms
8,676 KB
testcase_18 AC 16 ms
8,140 KB
testcase_19 AC 16 ms
8,236 KB
testcase_20 AC 19 ms
8,500 KB
testcase_21 AC 311 ms
38,588 KB
testcase_22 AC 231 ms
35,784 KB
testcase_23 AC 309 ms
39,860 KB
testcase_24 AC 128 ms
17,576 KB
testcase_25 AC 391 ms
38,456 KB
testcase_26 AC 379 ms
38,620 KB
testcase_27 AC 251 ms
36,460 KB
testcase_28 AC 254 ms
36,452 KB
testcase_29 AC 142 ms
19,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def kado(x,y,z):
    if x==z:
        return 0
    
    if y<x and y<z:
        return 1
    if y>x and y>z:
        return 1
    return 0

N,M=map(int,input().split())
A=list(map(int,input().split()))

for i in range(N-2):
    if A[i]==A[i+2]:
        print("No")
        exit()

E=[]

for i in range(N-1):
    if i%2==0:
        E.append((A[i],A[i+1]))
    else:
        E.append((A[i+1],A[i]))

# Kahnのアルゴリズム

EDGEIN=[0]*(M+1) # その点に入るEDGEの個数
EDGEOUTLIST=[[] for i in range(M+1)] # EDGEの行き先

for x,y in E:
    EDGEIN[y]+=1
    EDGEOUTLIST[x].append(y)

from collections import deque
QUE = deque()

for i in range(M+1):
    if EDGEIN[i]==0:
        QUE.append(i) # 行き先のない点をQUEに入れる
        
TOP_SORT=[]
while QUE:
    x=QUE.pop()
    TOP_SORT.append(x) # 行き先がない点を答えに入れる
    for to in EDGEOUTLIST[x]:
        EDGEIN[to]-=1 # 行き先がない点を削除し,そこから一歩先の点のEDGEINを一つ減らす.
        if EDGEIN[to]==0:
            QUE.appendleft(to)

T=[0]
for t in TOP_SORT:
    if t==0:
        continue
    T.append(t)

TOP_INV=[-1]*(M+1)

for i,x in enumerate(T):
    TOP_INV[x]=i

if -1 in TOP_INV:
    print("No")
else:
    print("Yes")
    print(*TOP_INV[1:])
0