結果

問題 No.1990 Candy Boxes
ユーザー mkawa2mkawa2
提出日時 2022-06-25 09:05:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,639 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 120,388 KB
最終ジャッジ日時 2023-08-12 23:13:57
合計ジャッジ時間 13,472 ms
ジャッジサーバーID
(参考情報)
judge11 / judge7
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,300 KB
testcase_01 AC 75 ms
71,160 KB
testcase_02 AC 76 ms
71,024 KB
testcase_03 AC 80 ms
71,028 KB
testcase_04 AC 77 ms
71,164 KB
testcase_05 AC 76 ms
71,036 KB
testcase_06 AC 77 ms
71,296 KB
testcase_07 AC 77 ms
71,268 KB
testcase_08 AC 78 ms
71,356 KB
testcase_09 AC 79 ms
71,096 KB
testcase_10 AC 78 ms
71,228 KB
testcase_11 AC 78 ms
71,032 KB
testcase_12 AC 115 ms
94,588 KB
testcase_13 AC 114 ms
94,652 KB
testcase_14 AC 97 ms
91,868 KB
testcase_15 AC 100 ms
95,836 KB
testcase_16 AC 101 ms
96,356 KB
testcase_17 AC 104 ms
98,872 KB
testcase_18 AC 105 ms
98,820 KB
testcase_19 AC 104 ms
97,264 KB
testcase_20 AC 114 ms
100,148 KB
testcase_21 AC 110 ms
100,280 KB
testcase_22 AC 100 ms
92,356 KB
testcase_23 AC 108 ms
94,004 KB
testcase_24 AC 108 ms
93,472 KB
testcase_25 AC 121 ms
104,268 KB
testcase_26 AC 216 ms
102,896 KB
testcase_27 AC 214 ms
102,992 KB
testcase_28 AC 261 ms
106,168 KB
testcase_29 AC 220 ms
105,824 KB
testcase_30 AC 235 ms
99,216 KB
testcase_31 AC 227 ms
105,984 KB
testcase_32 AC 178 ms
90,752 KB
testcase_33 AC 203 ms
99,308 KB
testcase_34 AC 148 ms
103,436 KB
testcase_35 AC 157 ms
103,192 KB
testcase_36 AC 156 ms
103,148 KB
testcase_37 AC 224 ms
102,564 KB
testcase_38 AC 204 ms
97,360 KB
testcase_39 AC 203 ms
99,608 KB
testcase_40 AC 226 ms
102,020 KB
testcase_41 AC 214 ms
102,076 KB
testcase_42 AC 184 ms
102,144 KB
testcase_43 AC 185 ms
97,352 KB
testcase_44 AC 185 ms
94,888 KB
testcase_45 AC 101 ms
95,912 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 77 ms
71,008 KB
testcase_50 AC 76 ms
71,356 KB
testcase_51 AC 75 ms
71,292 KB
testcase_52 AC 76 ms
71,404 KB
testcase_53 AC 76 ms
71,264 KB
testcase_54 WA -
testcase_55 AC 76 ms
71,376 KB
testcase_56 AC 78 ms
71,376 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 75 ms
71,268 KB
testcase_61 AC 77 ms
71,244 KB
testcase_62 AC 77 ms
71,292 KB
testcase_63 AC 77 ms
71,032 KB
testcase_64 AC 77 ms
71,316 KB
testcase_65 AC 180 ms
113,516 KB
testcase_66 WA -
testcase_67 AC 165 ms
102,992 KB
testcase_68 AC 186 ms
93,228 KB
testcase_69 AC 132 ms
102,856 KB
testcase_70 AC 156 ms
110,504 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 115 ms
99,320 KB
testcase_74 WA -
testcase_75 AC 101 ms
96,444 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)

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[i+1] & 1 and dd[j+1] & 1: heappush(q, j+1)
        dd[j] += dd[i]
        dd[j+1] += dd[i+1]
        dd[i] = dd[i+1] = 0
    # 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