結果

問題 No.904 サメトロ
ユーザー vwxyz
提出日時 2024-04-13 13:01:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 534 ms / 1,000 ms
コード長 363 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 76,568 KB
最終ジャッジ日時 2024-10-03 00:03:16
合計ジャッジ時間 14,083 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A,B=[],[]
for i in range(N-1):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
def check(A,B):
    sum_A=sum(A)
    sum_B=sum(B)
    return sum_A==sum_B and all(a+b<=sum_A for a,b in zip(A,B))
sum_A=sum(A)
sum_B=sum(B)
ans=0
for a in range(4*10**5):
    b=sum_A+a-sum_B
    if 0<=b and check(A+[a],B+[b]):
        ans+=1
print(ans)
0