結果

問題 No.1990 Candy Boxes
ユーザー mkawa2mkawa2
提出日時 2022-06-25 10:53:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 1,578 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 126,640 KB
最終ジャッジ日時 2024-04-30 18:12:48
合計ジャッジ時間 9,429 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,036 KB
testcase_01 AC 39 ms
53,620 KB
testcase_02 AC 35 ms
53,152 KB
testcase_03 AC 36 ms
53,364 KB
testcase_04 AC 39 ms
53,272 KB
testcase_05 AC 37 ms
53,940 KB
testcase_06 AC 36 ms
53,116 KB
testcase_07 AC 36 ms
52,992 KB
testcase_08 AC 37 ms
54,240 KB
testcase_09 AC 37 ms
52,928 KB
testcase_10 AC 38 ms
54,220 KB
testcase_11 AC 38 ms
54,376 KB
testcase_12 AC 84 ms
106,656 KB
testcase_13 AC 85 ms
107,124 KB
testcase_14 AC 59 ms
82,732 KB
testcase_15 AC 60 ms
86,976 KB
testcase_16 AC 61 ms
89,212 KB
testcase_17 AC 63 ms
92,468 KB
testcase_18 AC 65 ms
91,780 KB
testcase_19 AC 68 ms
90,852 KB
testcase_20 AC 69 ms
96,232 KB
testcase_21 AC 70 ms
95,360 KB
testcase_22 AC 60 ms
86,072 KB
testcase_23 AC 67 ms
94,388 KB
testcase_24 AC 65 ms
93,704 KB
testcase_25 AC 82 ms
100,300 KB
testcase_26 AC 180 ms
120,524 KB
testcase_27 AC 174 ms
120,492 KB
testcase_28 AC 236 ms
126,380 KB
testcase_29 AC 182 ms
126,640 KB
testcase_30 AC 164 ms
114,744 KB
testcase_31 AC 189 ms
126,372 KB
testcase_32 AC 137 ms
99,700 KB
testcase_33 AC 163 ms
114,284 KB
testcase_34 AC 98 ms
102,184 KB
testcase_35 AC 119 ms
114,604 KB
testcase_36 AC 118 ms
114,524 KB
testcase_37 AC 190 ms
118,860 KB
testcase_38 AC 166 ms
110,208 KB
testcase_39 AC 159 ms
114,028 KB
testcase_40 AC 172 ms
123,660 KB
testcase_41 AC 172 ms
122,580 KB
testcase_42 AC 137 ms
100,884 KB
testcase_43 AC 145 ms
112,512 KB
testcase_44 AC 153 ms
107,840 KB
testcase_45 AC 64 ms
88,680 KB
testcase_46 AC 170 ms
110,444 KB
testcase_47 AC 172 ms
103,040 KB
testcase_48 AC 165 ms
100,412 KB
testcase_49 AC 39 ms
52,824 KB
testcase_50 AC 40 ms
53,632 KB
testcase_51 AC 36 ms
54,220 KB
testcase_52 AC 35 ms
53,020 KB
testcase_53 AC 34 ms
54,420 KB
testcase_54 AC 35 ms
53,596 KB
testcase_55 AC 35 ms
53,732 KB
testcase_56 AC 34 ms
53,600 KB
testcase_57 AC 37 ms
53,208 KB
testcase_58 AC 38 ms
54,608 KB
testcase_59 AC 36 ms
53,864 KB
testcase_60 AC 37 ms
53,804 KB
testcase_61 AC 36 ms
53,876 KB
testcase_62 AC 35 ms
53,224 KB
testcase_63 AC 36 ms
53,224 KB
testcase_64 AC 36 ms
53,052 KB
testcase_65 AC 137 ms
119,524 KB
testcase_66 AC 135 ms
110,316 KB
testcase_67 AC 122 ms
114,380 KB
testcase_68 AC 139 ms
102,296 KB
testcase_69 AC 95 ms
115,056 KB
testcase_70 AC 111 ms
114,592 KB
testcase_71 AC 158 ms
111,380 KB
testcase_72 AC 180 ms
106,996 KB
testcase_73 AC 79 ms
103,844 KB
testcase_74 AC 163 ms
105,956 KB
testcase_75 AC 61 ms
89,660 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