結果

問題 No.1120 Strange Teacher
ユーザー roarisroaris
提出日時 2020-07-24 21:38:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 122 ms / 1,000 ms
コード長 618 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 100,016 KB
最終ジャッジ日時 2023-09-08 03:37:57
合計ジャッジ時間 4,782 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,536 KB
testcase_01 AC 72 ms
71,148 KB
testcase_02 AC 76 ms
75,892 KB
testcase_03 AC 81 ms
76,840 KB
testcase_04 AC 120 ms
99,732 KB
testcase_05 AC 119 ms
99,804 KB
testcase_06 AC 119 ms
99,740 KB
testcase_07 AC 120 ms
100,016 KB
testcase_08 AC 122 ms
99,768 KB
testcase_09 AC 72 ms
71,348 KB
testcase_10 AC 110 ms
100,008 KB
testcase_11 AC 108 ms
99,704 KB
testcase_12 AC 108 ms
100,004 KB
testcase_13 AC 120 ms
99,780 KB
testcase_14 AC 117 ms
99,748 KB
testcase_15 AC 116 ms
99,872 KB
testcase_16 AC 117 ms
99,772 KB
testcase_17 AC 116 ms
99,816 KB
testcase_18 AC 73 ms
71,308 KB
testcase_19 AC 118 ms
98,060 KB
testcase_20 AC 70 ms
71,144 KB
testcase_21 AC 73 ms
71,316 KB
testcase_22 AC 76 ms
71,508 KB
testcase_23 AC 72 ms
71,276 KB
testcase_24 AC 115 ms
99,444 KB
testcase_25 AC 72 ms
71,436 KB
testcase_26 AC 71 ms
71,524 KB
testcase_27 AC 71 ms
71,420 KB
testcase_28 AC 71 ms
71,144 KB
testcase_29 AC 71 ms
71,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [B[i]-A[i] for i in range(N)]

if N==2:
    if abs(C[0])!=abs(C[1]):
        print(-1)
    else:
        print(abs(C[0]))
    exit()
    
D = []

for i in range(1, N):
    if (C[0]-C[i])%2==1:
        print(-1)
        exit()
    
    D.append((C[0]-C[i])//2)

S = sum(D)

if (S-C[0])%(N-2)!=0:
    print(-1)
    exit()

x = (S-C[0])//(N-2)

if x<0:
    print(-1)
    exit()
    
ans = x

for Di in D:
    if x-Di<0:
        print(-1)
        exit()
        
    ans += x-Di

print(ans)
0