結果

問題 No.1120 Strange Teacher
ユーザー yuruhiyayuruhiya
提出日時 2020-07-23 08:32:42
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 396 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 29,168 KB
最終ジャッジ日時 2023-09-05 21:07:25
合計ジャッジ時間 5,644 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,044 KB
testcase_01 AC 77 ms
15,240 KB
testcase_02 AC 82 ms
15,168 KB
testcase_03 AC 90 ms
15,628 KB
testcase_04 AC 184 ms
28,912 KB
testcase_05 AC 181 ms
29,080 KB
testcase_06 AC 181 ms
28,920 KB
testcase_07 AC 179 ms
29,168 KB
testcase_08 AC 181 ms
28,936 KB
testcase_09 AC 77 ms
15,200 KB
testcase_10 AC 147 ms
28,100 KB
testcase_11 AC 150 ms
28,284 KB
testcase_12 AC 147 ms
28,368 KB
testcase_13 AC 151 ms
28,084 KB
testcase_14 AC 151 ms
28,316 KB
testcase_15 AC 150 ms
28,328 KB
testcase_16 AC 161 ms
29,168 KB
testcase_17 AC 157 ms
29,064 KB
testcase_18 AC 77 ms
15,088 KB
testcase_19 AC 181 ms
29,164 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 79 ms
15,136 KB
testcase_23 AC 79 ms
15,104 KB
testcase_24 AC 180 ms
28,428 KB
testcase_25 RE -
testcase_26 AC 80 ms
15,288 KB
testcase_27 AC 80 ms
15,096 KB
testcase_28 AC 79 ms
15,128 KB
testcase_29 AC 80 ms
15,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:9: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:15: 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

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

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