結果

問題 No.1120 Strange Teacher
ユーザー yuruhiyayuruhiya
提出日時 2020-07-23 08:30:29
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 324 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 11,496 KB
実行使用メモリ 29,108 KB
最終ジャッジ日時 2023-09-05 21:04:53
合計ジャッジ時間 6,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,040 KB
testcase_01 AC 83 ms
15,104 KB
testcase_02 AC 81 ms
15,304 KB
testcase_03 AC 89 ms
15,724 KB
testcase_04 AC 185 ms
28,876 KB
testcase_05 AC 183 ms
28,768 KB
testcase_06 AC 185 ms
28,876 KB
testcase_07 AC 183 ms
28,776 KB
testcase_08 AC 182 ms
28,896 KB
testcase_09 AC 78 ms
15,144 KB
testcase_10 AC 150 ms
28,092 KB
testcase_11 AC 150 ms
28,088 KB
testcase_12 AC 149 ms
28,160 KB
testcase_13 AC 150 ms
28,048 KB
testcase_14 AC 150 ms
28,216 KB
testcase_15 AC 150 ms
28,092 KB
testcase_16 AC 157 ms
28,772 KB
testcase_17 AC 161 ms
29,092 KB
testcase_18 AC 78 ms
15,144 KB
testcase_19 AC 183 ms
29,108 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 79 ms
15,048 KB
testcase_23 AC 80 ms
14,960 KB
testcase_24 AC 184 ms
28,472 KB
testcase_25 RE -
testcase_26 AC 79 ms
15,200 KB
testcase_27 AC 78 ms
15,052 KB
testcase_28 AC 78 ms
15,056 KB
testcase_29 AC 78 ms
15,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:7: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:13: 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

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