結果

問題 No.1990 Candy Boxes
ユーザー mkawa2mkawa2
提出日時 2022-06-25 10:46:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 120,200 KB
最終ジャッジ日時 2023-08-12 23:14:27
合計ジャッジ時間 13,255 ms
ジャッジサーバーID
(参考情報)
judge8 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,336 KB
testcase_01 AC 69 ms
71,496 KB
testcase_02 AC 71 ms
71,364 KB
testcase_03 AC 71 ms
71,124 KB
testcase_04 AC 70 ms
71,076 KB
testcase_05 AC 69 ms
71,324 KB
testcase_06 AC 69 ms
71,116 KB
testcase_07 AC 70 ms
71,072 KB
testcase_08 AC 72 ms
71,304 KB
testcase_09 AC 72 ms
71,080 KB
testcase_10 AC 72 ms
71,344 KB
testcase_11 AC 69 ms
71,364 KB
testcase_12 AC 115 ms
94,932 KB
testcase_13 AC 113 ms
94,956 KB
testcase_14 AC 90 ms
91,688 KB
testcase_15 AC 96 ms
96,144 KB
testcase_16 AC 94 ms
96,204 KB
testcase_17 AC 95 ms
98,944 KB
testcase_18 AC 97 ms
99,424 KB
testcase_19 AC 98 ms
97,644 KB
testcase_20 AC 103 ms
100,336 KB
testcase_21 AC 101 ms
100,060 KB
testcase_22 AC 95 ms
92,504 KB
testcase_23 AC 102 ms
94,456 KB
testcase_24 AC 102 ms
93,824 KB
testcase_25 AC 112 ms
104,272 KB
testcase_26 AC 195 ms
102,780 KB
testcase_27 AC 203 ms
102,988 KB
testcase_28 AC 265 ms
106,316 KB
testcase_29 AC 209 ms
105,740 KB
testcase_30 AC 187 ms
99,164 KB
testcase_31 AC 209 ms
106,120 KB
testcase_32 AC 168 ms
90,820 KB
testcase_33 AC 190 ms
99,584 KB
testcase_34 AC 133 ms
103,340 KB
testcase_35 AC 144 ms
103,236 KB
testcase_36 AC 149 ms
103,216 KB
testcase_37 AC 213 ms
102,784 KB
testcase_38 AC 197 ms
97,740 KB
testcase_39 AC 187 ms
99,804 KB
testcase_40 AC 199 ms
102,152 KB
testcase_41 AC 195 ms
102,344 KB
testcase_42 AC 169 ms
101,948 KB
testcase_43 AC 175 ms
97,480 KB
testcase_44 AC 179 ms
94,812 KB
testcase_45 AC 95 ms
96,112 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 72 ms
71,276 KB
testcase_50 AC 70 ms
71,072 KB
testcase_51 AC 70 ms
71,292 KB
testcase_52 AC 68 ms
71,172 KB
testcase_53 AC 68 ms
71,416 KB
testcase_54 AC 70 ms
71,188 KB
testcase_55 AC 68 ms
71,172 KB
testcase_56 AC 69 ms
71,524 KB
testcase_57 AC 70 ms
71,272 KB
testcase_58 AC 69 ms
71,176 KB
testcase_59 AC 69 ms
71,176 KB
testcase_60 AC 69 ms
71,324 KB
testcase_61 AC 67 ms
71,356 KB
testcase_62 AC 67 ms
71,364 KB
testcase_63 AC 69 ms
71,276 KB
testcase_64 AC 68 ms
71,364 KB
testcase_65 AC 163 ms
113,584 KB
testcase_66 AC 162 ms
100,628 KB
testcase_67 AC 151 ms
103,096 KB
testcase_68 AC 170 ms
93,464 KB
testcase_69 AC 117 ms
102,976 KB
testcase_70 AC 138 ms
110,744 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 111 ms
99,724 KB
testcase_74 WA -
testcase_75 AC 91 ms
96,552 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

from heapq import *

n = II()
aa = [0]+LI()

now = 0
for i in range(n):
    now = aa[i+1]-now
    if now < 0:
        print("No")
        exit()
if now:
    print("No")
    exit()

q = []
dd = []
for i in range(n):
    dd.append(aa[i+1]-aa[i])
    if dd[-1] & 1 == 0: heappush(q, i)
dd.append(0)
# pDB(q, dd)

def move(i,j):
    dd[j] += 1
    dd[i] -= 1

for i in range(n-1):
    if dd[i] & 1 == 0: continue
    if dd[i+1] & 1 == 0:
        d = dd[i]
        dd[i] -= d
        dd[i+2] += d
    else:
        while q and (q[0] <= i or dd[q[0]] & 1): heappop(q)
        if not q:
            print("No")
            exit()
        j = q[0]
        if dd[j+1] & 1: heappush(q, j+1)
        move(i,j)
        move(i+1,j+1)
    # pDB(q, dd)

def ng(si):
    now = 0
    for i in range(si, n, 2):
        now += dd[i]
        if now < 0: return True
    return False

print("No" if ng(0) or ng(1) or dd[-2] else "Yes")
0