結果

問題 No.2812 Plus Minus Blackboard
ユーザー rlangevinrlangevin
提出日時 2024-07-19 21:42:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 431 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 103,936 KB
最終ジャッジ日時 2024-07-21 20:26:49
合計ジャッジ時間 6,562 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
52,224 KB
testcase_01 AC 50 ms
52,472 KB
testcase_02 AC 42 ms
52,224 KB
testcase_03 AC 368 ms
103,936 KB
testcase_04 AC 260 ms
92,800 KB
testcase_05 AC 344 ms
103,680 KB
testcase_06 AC 170 ms
79,540 KB
testcase_07 AC 159 ms
78,464 KB
testcase_08 AC 152 ms
78,384 KB
testcase_09 AC 315 ms
98,304 KB
testcase_10 AC 153 ms
77,184 KB
testcase_11 AC 249 ms
90,608 KB
testcase_12 AC 220 ms
87,040 KB
testcase_13 AC 365 ms
103,680 KB
testcase_14 AC 186 ms
81,152 KB
testcase_15 AC 149 ms
76,928 KB
testcase_16 AC 340 ms
101,376 KB
testcase_17 AC 186 ms
81,792 KB
testcase_18 AC 173 ms
79,232 KB
testcase_19 AC 295 ms
95,488 KB
testcase_20 AC 152 ms
78,296 KB
testcase_21 AC 362 ms
103,936 KB
testcase_22 AC 337 ms
101,120 KB
testcase_23 AC 42 ms
52,224 KB
testcase_24 AC 42 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

N = int(input())
A = list(map(int, input().split()))
p, m = [], []
for a in A:
    if a > 0:
        heappush(p, a)
    elif a < 0:
        heappush(m, -a)
        
while p and m:
    p0 = heappop(p)
    m0 = heappop(m)
    if p0 == m0:
        continue
    if p0 > m0:
        heappush(p, p0 - m0)
    else:
        heappush(m, m0 - p0)
        
if len(p) + len(m) <= 1:
    print("Yes")
else:
    print("No")
0