結果

問題 No.904 サメトロ
ユーザー FromBooskaFromBooska
提出日時 2023-04-18 11:28:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 1,000 ms
コード長 568 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 58,216 KB
最終ジャッジ日時 2024-04-21 10:45:14
合計ジャッジ時間 3,350 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
57,984 KB
testcase_01 AC 40 ms
51,584 KB
testcase_02 AC 45 ms
57,728 KB
testcase_03 AC 44 ms
57,984 KB
testcase_04 AC 46 ms
58,112 KB
testcase_05 AC 40 ms
51,712 KB
testcase_06 AC 46 ms
58,112 KB
testcase_07 AC 46 ms
57,728 KB
testcase_08 AC 47 ms
58,216 KB
testcase_09 AC 41 ms
51,840 KB
testcase_10 AC 45 ms
57,980 KB
testcase_11 AC 49 ms
57,600 KB
testcase_12 AC 40 ms
51,840 KB
testcase_13 AC 40 ms
52,480 KB
testcase_14 AC 45 ms
57,984 KB
testcase_15 AC 41 ms
51,840 KB
testcase_16 AC 46 ms
57,728 KB
testcase_17 AC 41 ms
51,968 KB
testcase_18 AC 39 ms
52,224 KB
testcase_19 AC 40 ms
52,352 KB
testcase_20 AC 40 ms
51,712 KB
testcase_21 AC 45 ms
58,112 KB
testcase_22 AC 45 ms
58,112 KB
testcase_23 AC 45 ms
57,984 KB
testcase_24 AC 44 ms
57,472 KB
testcase_25 AC 41 ms
52,424 KB
testcase_26 AC 45 ms
57,600 KB
testcase_27 AC 47 ms
57,984 KB
testcase_28 AC 41 ms
52,480 KB
testcase_29 AC 41 ms
52,096 KB
testcase_30 AC 40 ms
51,968 KB
testcase_31 AC 40 ms
51,840 KB
testcase_32 AC 41 ms
52,224 KB
testcase_33 AC 41 ms
52,096 KB
testcase_34 AC 40 ms
51,840 KB
testcase_35 AC 45 ms
57,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# A1, B1にはminimum to maxがある
# 入力例1
# A1 minは、たとえばB2-A3
# A1 maxは、B2+B3

N = int(input())
A = []
B = []
for i in range(N-1):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

sumA = sum(A)
sumB = sum(B)
A1_min = 0
A1_max = sumB
B1_min = 0
B1_max = sumA

for i in range(N-1):
    A1_min = max(A1_min, B[i]-(sumA-A[i]))
    B1_min = max(B1_min, A[i]-(sumB-B[i]))

ans = 0
for a in range(A1_min, A1_max+1):
    b = sumA + a - sumB
    if B1_min <= b <= B1_max:
        ans += 1
        #print('a', a, 'b', b)
print(ans)
0