結果

問題 No.1120 Strange Teacher
ユーザー yuruhiyayuruhiya
提出日時 2020-07-23 08:33:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 187 ms / 1,000 ms
コード長 407 bytes
コンパイル時間 38 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 29,184 KB
最終ジャッジ日時 2023-09-05 21:07:31
合計ジャッジ時間 5,335 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,332 KB
testcase_01 AC 79 ms
15,156 KB
testcase_02 AC 83 ms
15,056 KB
testcase_03 AC 88 ms
15,696 KB
testcase_04 AC 186 ms
29,112 KB
testcase_05 AC 184 ms
28,944 KB
testcase_06 AC 187 ms
28,868 KB
testcase_07 AC 185 ms
29,100 KB
testcase_08 AC 183 ms
29,076 KB
testcase_09 AC 79 ms
15,316 KB
testcase_10 AC 150 ms
28,232 KB
testcase_11 AC 151 ms
28,208 KB
testcase_12 AC 149 ms
28,152 KB
testcase_13 AC 151 ms
28,308 KB
testcase_14 AC 152 ms
28,180 KB
testcase_15 AC 152 ms
28,292 KB
testcase_16 AC 159 ms
28,864 KB
testcase_17 AC 159 ms
28,972 KB
testcase_18 AC 79 ms
15,112 KB
testcase_19 AC 185 ms
29,184 KB
testcase_20 AC 77 ms
15,140 KB
testcase_21 AC 79 ms
15,224 KB
testcase_22 AC 80 ms
15,272 KB
testcase_23 AC 80 ms
15,036 KB
testcase_24 AC 181 ms
28,508 KB
testcase_25 AC 109 ms
15,052 KB
testcase_26 AC 81 ms
15,132 KB
testcase_27 AC 79 ms
15,240 KB
testcase_28 AC 82 ms
15,388 KB
testcase_29 AC 80 ms
15,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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