結果

問題 No.1120 Strange Teacher
ユーザー 双六双六
提出日時 2020-07-22 21:39:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 711 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 103,352 KB
最終ジャッジ日時 2023-09-04 16:25:00
合計ジャッジ時間 5,393 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,544 KB
testcase_01 AC 95 ms
71,524 KB
testcase_02 AC 102 ms
76,868 KB
testcase_03 AC 107 ms
77,372 KB
testcase_04 AC 136 ms
103,332 KB
testcase_05 AC 137 ms
103,180 KB
testcase_06 AC 136 ms
103,308 KB
testcase_07 AC 137 ms
103,236 KB
testcase_08 AC 135 ms
103,308 KB
testcase_09 AC 94 ms
71,512 KB
testcase_10 AC 133 ms
102,760 KB
testcase_11 AC 133 ms
102,776 KB
testcase_12 AC 133 ms
102,924 KB
testcase_13 AC 133 ms
102,752 KB
testcase_14 AC 134 ms
102,888 KB
testcase_15 AC 133 ms
102,748 KB
testcase_16 AC 133 ms
102,900 KB
testcase_17 AC 134 ms
102,744 KB
testcase_18 AC 94 ms
71,672 KB
testcase_19 AC 135 ms
103,352 KB
testcase_20 AC 93 ms
71,620 KB
testcase_21 AC 96 ms
71,676 KB
testcase_22 AC 96 ms
71,492 KB
testcase_23 AC 98 ms
71,624 KB
testcase_24 AC 135 ms
102,636 KB
testcase_25 AC 95 ms
71,604 KB
testcase_26 AC 93 ms
71,680 KB
testcase_27 AC 94 ms
71,628 KB
testcase_28 AC 96 ms
71,676 KB
testcase_29 AC 98 ms
71,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = getlist()
	for i in range(N):
		A[i] -= B[i]

	if N == 2:
		if sum(A) == 0:
			print(abs(A[0]))
		else:
			print(-1)
		return

	dif = sum(A)
	if dif % (N - 2) != 0:
		print(-1)
		return

	n = int(dif // (N - 2))
	# 2 * aplha = n - A[i]
	cnt = 0
	for i in range(N):
		if (n - A[i]) % 2 == 1 or n - A[i] < 0:
			print(-1)
			return
		cnt += int((n - A[i]) // 2)

	if cnt == n:
		print(n)
	else:
		print(-1)


if __name__ == '__main__':
	main()
0