結果

問題 No.904 サメトロ
ユーザー FromBooskaFromBooska
提出日時 2023-03-08 19:07:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 58,368 KB
最終ジャッジ日時 2024-09-18 02:38:28
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

# 3つの制約がある
# sum(A) = sum(B)、これによりA1とB1の差が決まる
# A1_max = sum(B2:)、もちろん下限は0
# B1_max = sum(A2:)

N = int(input())
sumA, sumB = 0, 0
for i in range(N-1):
    a, b = map(int, input().split())
    sumA += a
    sumB += b

# 計算式でいけると思うが愚直にやった
count = 0
for A1 in range(0, sumB+1):
    B1 = A1 + sumA - sumB
    #print('A1', A1, 'B1', B1, 0 <= B1 <= sumA)
    if 0 <= B1 <= sumA:
        count += 1
if N == 2:
    print(1)
else:
    print(count)
0