結果

問題 No.1370 置換門松列
ユーザー 👑 tamatotamato
提出日時 2021-02-26 10:57:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,744 KB
実行使用メモリ 97,016 KB
最終ジャッジ日時 2023-10-12 21:07:09
合計ジャッジ時間 5,136 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,680 KB
testcase_01 AC 75 ms
71,352 KB
testcase_02 AC 73 ms
71,536 KB
testcase_03 AC 72 ms
71,244 KB
testcase_04 AC 72 ms
71,296 KB
testcase_05 AC 73 ms
71,336 KB
testcase_06 AC 74 ms
71,260 KB
testcase_07 AC 76 ms
71,348 KB
testcase_08 AC 75 ms
71,640 KB
testcase_09 AC 76 ms
71,572 KB
testcase_10 AC 75 ms
71,496 KB
testcase_11 AC 74 ms
71,352 KB
testcase_12 AC 75 ms
71,616 KB
testcase_13 AC 76 ms
71,340 KB
testcase_14 AC 74 ms
71,352 KB
testcase_15 AC 75 ms
71,348 KB
testcase_16 AC 74 ms
71,568 KB
testcase_17 AC 76 ms
71,348 KB
testcase_18 AC 76 ms
71,344 KB
testcase_19 AC 74 ms
71,596 KB
testcase_20 AC 75 ms
71,356 KB
testcase_21 AC 147 ms
97,008 KB
testcase_22 AC 120 ms
96,280 KB
testcase_23 AC 147 ms
96,184 KB
testcase_24 AC 100 ms
90,920 KB
testcase_25 AC 173 ms
97,016 KB
testcase_26 AC 171 ms
96,636 KB
testcase_27 AC 117 ms
94,924 KB
testcase_28 AC 115 ms
94,808 KB
testcase_29 AC 102 ms
90,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

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

    adj = [[] for _ in range(M+1)]
    in_num = [0] * (M+1)
    for i in range(N-1):
        u, v = A[i], A[i+1]
        if i & 1:
            adj[v].append(u)
            in_num[u] += 1
        else:
            adj[u].append(v)
            in_num[v] += 1
    st = []
    for v in range(1, M+1):
        if in_num[v] == 0:
            st.append(v)
    cnt = 0
    ans = [0] * M
    seen = [0] * (M+1)
    while st:
        v = st.pop()
        if seen[v]:
            continue
        else:
            seen[v] = 1
        cnt += 1
        ans[v-1] = cnt
        for u in adj[v]:
            in_num[u] -= 1
            if in_num[u] == 0:
                st.append(u)
    if cnt == M:
        print("Yes")
        print(*ans)
    else:
        print("No")


if __name__ == '__main__':
    main()
0