結果

問題 No.1120 Strange Teacher
ユーザー takakintakakin
提出日時 2020-07-25 22:15:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 151 ms / 1,000 ms
コード長 485 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 23,880 KB
最終ジャッジ日時 2023-09-10 02:00:46
合計ジャッジ時間 4,006 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,780 KB
testcase_01 AC 16 ms
7,864 KB
testcase_02 AC 18 ms
8,252 KB
testcase_03 AC 29 ms
9,772 KB
testcase_04 AC 151 ms
23,648 KB
testcase_05 AC 143 ms
23,696 KB
testcase_06 AC 142 ms
23,572 KB
testcase_07 AC 142 ms
23,748 KB
testcase_08 AC 140 ms
23,760 KB
testcase_09 AC 16 ms
7,796 KB
testcase_10 AC 80 ms
23,856 KB
testcase_11 AC 80 ms
23,852 KB
testcase_12 AC 81 ms
23,708 KB
testcase_13 AC 79 ms
23,656 KB
testcase_14 AC 80 ms
23,640 KB
testcase_15 AC 81 ms
23,656 KB
testcase_16 AC 140 ms
23,752 KB
testcase_17 AC 147 ms
23,700 KB
testcase_18 AC 15 ms
7,896 KB
testcase_19 AC 133 ms
23,880 KB
testcase_20 AC 16 ms
7,808 KB
testcase_21 AC 16 ms
7,900 KB
testcase_22 AC 16 ms
7,908 KB
testcase_23 AC 16 ms
7,868 KB
testcase_24 AC 136 ms
20,648 KB
testcase_25 AC 16 ms
7,944 KB
testcase_26 AC 16 ms
7,864 KB
testcase_27 AC 16 ms
7,808 KB
testcase_28 AC 16 ms
7,812 KB
testcase_29 AC 16 ms
7,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

if n==2:
	if sum(A)==sum(B):
		print(abs(A[0]-B[0]))
	else:
		print(-1)
else:
	d=sum(A)-sum(B)
	if d<0 or d%(n-2)!=0:
		print(-1)
	else:
		ans=d//(n-2)
		ct=0
		Chk=True
		for i in range(n):
			if (B[i]-A[i]+ans)%2!=0 or (B[i]-A[i]+ans)<0:
				Chk=False
			ct+=(B[i]-A[i]+ans)//2
		if Chk==False or ct!=ans:
			print(-1)
		else:
			print(ans)
0