結果

問題 No.1120 Strange Teacher
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2020-07-22 23:25:53
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 805 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 23,884 KB
最終ジャッジ日時 2023-09-05 04:40:06
合計ジャッジ時間 3,520 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,952 KB
testcase_01 AC 16 ms
7,892 KB
testcase_02 AC 17 ms
8,252 KB
testcase_03 AC 27 ms
9,860 KB
testcase_04 AC 123 ms
23,648 KB
testcase_05 AC 104 ms
23,648 KB
testcase_06 AC 98 ms
23,604 KB
testcase_07 AC 99 ms
23,620 KB
testcase_08 AC 98 ms
23,636 KB
testcase_09 AC 17 ms
7,840 KB
testcase_10 AC 76 ms
23,732 KB
testcase_11 AC 75 ms
23,884 KB
testcase_12 AC 74 ms
23,864 KB
testcase_13 AC 73 ms
23,556 KB
testcase_14 AC 73 ms
23,612 KB
testcase_15 AC 73 ms
23,652 KB
testcase_16 AC 73 ms
23,692 KB
testcase_17 AC 73 ms
23,576 KB
testcase_18 AC 16 ms
7,740 KB
testcase_19 AC 97 ms
23,768 KB
testcase_20 AC 16 ms
8,192 KB
testcase_21 AC 15 ms
8,192 KB
testcase_22 AC 16 ms
8,108 KB
testcase_23 AC 15 ms
7,812 KB
testcase_24 AC 124 ms
20,616 KB
testcase_25 AC 16 ms
8,196 KB
testcase_26 AC 16 ms
8,200 KB
testcase_27 AC 16 ms
7,820 KB
testcase_28 AC 16 ms
7,852 KB
testcase_29 AC 16 ms
8,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sa = sum(a)
sb = sum(b)
if n == 2:
    dif = a[0]-b[0]
    if a[1]+dif == b[1]:
        print(abs(dif))
    else:
        print(-1)
    exit()
if sb > sa or (sa-sb)%(n-2):
    print(-1)

else:
    count = (sa-sb)//(n-2)
    
    x = 0
    for i in range(n):
        dif = a[i]-b[i]
        
        if dif == count:
            continue
        if dif >= 0:
            if (count-dif)%2 or dif > count:
                print(-1)
                exit()
            x += (count-dif)//2
        else:
            if (count+dif)%2 or count+dif < 0:
                print(-1)
                exit()
            x += -dif + (count+dif)//2
        
    if x == count:
        print(count)
    else:
        print(-1)
        
0