結果

問題 No.1120 Strange Teacher
ユーザー yuruhiya
提出日時 2020-07-23 08:33:00
言語 Ruby
(3.4.1)
結果
AC  
実行時間 202 ms / 1,000 ms
コード長 407 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2024-06-23 16:30:12
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:12: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:18: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

n = gets.to_i
a = gets.split.map &:to_i
b = gets.split.map &:to_i

if n == 2
	puts (a[0] - b[0]) == (b[1] - a[1]) ? (a[0] - b[0]).abs : -1
	exit
end

minus = a.sum - b.sum
if minus % (n - 2) != 0
	puts -1
	exit
end
cnt = minus / (n - 2)
a = a.map { |i| i -= cnt }
if (0...n).any? { |i| a[i] > b[i] || (b[i] - a[i]) % 2 == 1 }
	puts -1
	exit
end

puts (0...n).sum { |i| (b[i] - a[i]) / 2 } == cnt ? cnt : -1
0