結果

問題 No.1370 置換門松列
ユーザー mkawa2mkawa2
提出日時 2022-06-24 08:24:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 1,419 ms
コンパイル使用メモリ 86,244 KB
実行使用メモリ 101,232 KB
最終ジャッジ日時 2023-10-12 21:08:18
合計ジャッジ時間 6,106 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,056 KB
testcase_01 AC 76 ms
71,056 KB
testcase_02 AC 77 ms
70,796 KB
testcase_03 AC 76 ms
71,016 KB
testcase_04 AC 75 ms
71,156 KB
testcase_05 AC 74 ms
70,804 KB
testcase_06 AC 74 ms
70,948 KB
testcase_07 AC 74 ms
70,956 KB
testcase_08 AC 74 ms
71,000 KB
testcase_09 AC 77 ms
71,096 KB
testcase_10 AC 74 ms
70,960 KB
testcase_11 AC 74 ms
70,908 KB
testcase_12 AC 73 ms
71,044 KB
testcase_13 AC 73 ms
71,072 KB
testcase_14 AC 74 ms
71,028 KB
testcase_15 AC 72 ms
70,976 KB
testcase_16 AC 75 ms
71,004 KB
testcase_17 AC 75 ms
71,200 KB
testcase_18 AC 73 ms
70,936 KB
testcase_19 AC 74 ms
70,948 KB
testcase_20 AC 74 ms
70,776 KB
testcase_21 AC 152 ms
100,328 KB
testcase_22 AC 123 ms
95,796 KB
testcase_23 AC 153 ms
101,232 KB
testcase_24 AC 102 ms
90,876 KB
testcase_25 AC 186 ms
100,196 KB
testcase_26 AC 188 ms
100,196 KB
testcase_27 AC 122 ms
95,648 KB
testcase_28 AC 122 ms
95,544 KB
testcase_29 AC 110 ms
89,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

n, m = LI()
aa = LI1()

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

to = [[] for _ in range(m)]
deg = [0]*m

for i in range(n-1):
    u, v = aa[i], aa[i+1]
    if i & 1:
        to[v].append(u)
        deg[u] += 1
    else:
        to[u].append(v)
        deg[v] += 1
# pDB(to)

st = [u for u in range(m) if deg[u] == 0]
uu = []
while st:
    u = st.pop()
    uu.append(u)
    for v in to[u]:
        deg[v] -= 1
        if deg[v] == 0:
            st.append(v)

if len(uu) == m:
    print("Yes")
    ans = [0]*m
    for i, u in enumerate(uu):
        ans[u] = i+1
    print(*ans)
    # xx=[ans[a] for a in aa]
    # pDB(*xx)
else:
    print("No")
0