結果

問題 No.1990 Candy Boxes
ユーザー mkawa2mkawa2
提出日時 2022-06-25 10:53:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,578 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 120,052 KB
最終ジャッジ日時 2023-08-12 23:14:48
合計ジャッジ時間 14,292 ms
ジャッジサーバーID
(参考情報)
judge2 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,208 KB
testcase_01 AC 77 ms
71,088 KB
testcase_02 AC 76 ms
71,212 KB
testcase_03 AC 74 ms
71,168 KB
testcase_04 AC 74 ms
71,212 KB
testcase_05 AC 72 ms
71,220 KB
testcase_06 AC 74 ms
71,184 KB
testcase_07 AC 75 ms
70,916 KB
testcase_08 AC 76 ms
70,908 KB
testcase_09 AC 77 ms
71,388 KB
testcase_10 AC 73 ms
71,240 KB
testcase_11 AC 73 ms
71,120 KB
testcase_12 AC 119 ms
94,796 KB
testcase_13 AC 112 ms
94,904 KB
testcase_14 AC 93 ms
91,672 KB
testcase_15 AC 98 ms
95,928 KB
testcase_16 AC 98 ms
96,392 KB
testcase_17 AC 105 ms
99,108 KB
testcase_18 AC 100 ms
98,836 KB
testcase_19 AC 98 ms
97,560 KB
testcase_20 AC 103 ms
100,528 KB
testcase_21 AC 104 ms
100,320 KB
testcase_22 AC 97 ms
92,392 KB
testcase_23 AC 103 ms
94,300 KB
testcase_24 AC 103 ms
93,700 KB
testcase_25 AC 115 ms
104,336 KB
testcase_26 AC 218 ms
102,708 KB
testcase_27 AC 217 ms
103,080 KB
testcase_28 AC 278 ms
105,984 KB
testcase_29 AC 212 ms
106,016 KB
testcase_30 AC 197 ms
99,124 KB
testcase_31 AC 222 ms
105,976 KB
testcase_32 AC 177 ms
90,936 KB
testcase_33 AC 202 ms
99,348 KB
testcase_34 AC 141 ms
103,272 KB
testcase_35 AC 155 ms
103,488 KB
testcase_36 AC 152 ms
103,420 KB
testcase_37 AC 224 ms
102,804 KB
testcase_38 AC 204 ms
97,684 KB
testcase_39 AC 201 ms
99,808 KB
testcase_40 AC 217 ms
102,292 KB
testcase_41 AC 208 ms
102,284 KB
testcase_42 AC 178 ms
102,144 KB
testcase_43 AC 181 ms
97,508 KB
testcase_44 AC 185 ms
94,712 KB
testcase_45 AC 96 ms
96,052 KB
testcase_46 AC 204 ms
98,364 KB
testcase_47 AC 223 ms
116,160 KB
testcase_48 AC 216 ms
100,392 KB
testcase_49 AC 76 ms
71,072 KB
testcase_50 AC 77 ms
71,188 KB
testcase_51 AC 74 ms
71,240 KB
testcase_52 AC 74 ms
71,196 KB
testcase_53 AC 77 ms
71,420 KB
testcase_54 AC 74 ms
71,204 KB
testcase_55 AC 72 ms
71,220 KB
testcase_56 AC 77 ms
71,196 KB
testcase_57 AC 76 ms
71,204 KB
testcase_58 AC 76 ms
71,152 KB
testcase_59 AC 76 ms
71,324 KB
testcase_60 AC 77 ms
71,404 KB
testcase_61 AC 78 ms
71,192 KB
testcase_62 AC 77 ms
70,940 KB
testcase_63 AC 78 ms
70,944 KB
testcase_64 AC 73 ms
71,244 KB
testcase_65 AC 179 ms
113,472 KB
testcase_66 AC 171 ms
100,576 KB
testcase_67 AC 162 ms
103,116 KB
testcase_68 AC 184 ms
93,512 KB
testcase_69 AC 127 ms
102,972 KB
testcase_70 AC 151 ms
110,820 KB
testcase_71 AC 205 ms
98,544 KB
testcase_72 AC 234 ms
120,052 KB
testcase_73 AC 113 ms
99,484 KB
testcase_74 AC 193 ms
96,064 KB
testcase_75 AC 98 ms
96,560 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)

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

# print(dd)
print("Yes")
0