結果

問題 No.1120 Strange Teacher
ユーザー lloyzlloyz
提出日時 2023-05-14 00:25:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 1,000 ms
コード長 561 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 104,016 KB
最終ジャッジ日時 2024-05-07 02:52:54
合計ジャッジ時間 3,419 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,248 KB
testcase_01 AC 41 ms
52,992 KB
testcase_02 AC 41 ms
59,324 KB
testcase_03 AC 50 ms
66,160 KB
testcase_04 AC 88 ms
103,436 KB
testcase_05 AC 91 ms
103,784 KB
testcase_06 AC 90 ms
103,400 KB
testcase_07 AC 89 ms
103,604 KB
testcase_08 AC 89 ms
103,624 KB
testcase_09 AC 37 ms
53,112 KB
testcase_10 AC 84 ms
103,960 KB
testcase_11 AC 86 ms
103,484 KB
testcase_12 AC 86 ms
103,436 KB
testcase_13 AC 86 ms
103,744 KB
testcase_14 AC 85 ms
104,016 KB
testcase_15 AC 85 ms
103,636 KB
testcase_16 AC 84 ms
103,772 KB
testcase_17 AC 85 ms
103,352 KB
testcase_18 AC 36 ms
53,156 KB
testcase_19 AC 92 ms
100,768 KB
testcase_20 AC 37 ms
52,316 KB
testcase_21 AC 37 ms
52,892 KB
testcase_22 AC 37 ms
52,684 KB
testcase_23 AC 38 ms
52,468 KB
testcase_24 AC 86 ms
102,668 KB
testcase_25 AC 37 ms
52,284 KB
testcase_26 AC 36 ms
52,824 KB
testcase_27 AC 37 ms
53,480 KB
testcase_28 AC 36 ms
53,084 KB
testcase_29 AC 37 ms
52,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

D = []
for i in range(n):
    D.append(B[i] - A[i])
sumD = sum(D)
if n == 2:
    if sumD == 0:
        print(abs(D[0]))
    else:
        print(-1)
elif sumD <= 0 and abs(sumD) % (n - 2) == 0:
    cnt = abs(sumD) // (n - 2)
    res = 0
    for i in range(n):
        if D[i] + cnt < 0 or (D[i] + cnt) % 2 != 0:
            print(-1)
            exit()
        res += (D[i] + cnt) // 2
    if res == cnt:
        print(cnt)
    else:
        print(-1)
else:
    print(-1)
0