結果

問題 No.1242 高橋君とすごろく
ユーザー ntuda
提出日時 2025-03-27 21:46:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,611 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 54,692 KB
最終ジャッジ日時 2025-03-27 21:46:29
合計ジャッジ時間 3,064 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
Q = []
N, K = map(int, input().split())
A = [i - 1 for i in list(map(int, input().split()))]
pa = 10 ** 18 + 10
X = [1] * 6
j = K - 1
i = K - 1
while i >= 0:
    if Q:
        if -Q[0] == A[i]:
            a = -heappop(Q)
            i -= 1
        elif -Q[0] > A[i]:
            a = -heappop(Q)
        else:
            a = A[i]
            i -= 1
    else:
        a = A[i]
        i -= 1
    while i + 1 < j and A[j] - A[i + 1] >= 6:
        j -= 1
    if i + 1 < j:
        b = A[j]
        for k in range(5,0,-2):
            if b - a == k or X[(a + k) % 6] == 0:
                c = a - (7 - k) // 2
                if c >= 0:
                    if X[c % 6] == 1:
                        X[a % 6] = 0
                        X[(a + k) % 6] = 0
                    if X[c % 6] == 1:
                        X[c % 6] = 0
                        heappush(Q,-c)
                        for l in range(1,6):
                            if c - l>= 0 and X[(c-l) % 6] == 0:
                                heappush(Q,-(c-l))

while Q:
    a = -heappop(Q)
    for k in range(5, 0, -2):
        if X[(a + k) % 6] == 0:
            c = a - (7 - k) // 2
            if c >= 0:
                if X[c % 6] == 1:
                    X[a % 6] = 0
                    X[(a + k) % 6] = 0
                if X[c % 6] == 1:
                    X[c % 6] = 0
                    heappush(Q,-c)
                    for l in range(1, 6):
                        if c - l >= 0 and X[(c - l) % 6] == 0:
                            heappush(Q, -(c - l))

if X[0] == 0:
    print("No")
else:
    print("Yes")
0