結果

問題 No.1120 Strange Teacher
ユーザー tomeruntomerun
提出日時 2020-07-22 21:41:38
言語 Crystal
(1.11.2)
結果
AC  
実行時間 30 ms / 1,000 ms
コード長 390 bytes
コンパイル時間 17,172 ms
コンパイル使用メモリ 254,280 KB
実行使用メモリ 18,572 KB
最終ジャッジ日時 2023-09-13 11:22:24
合計ジャッジ時間 19,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,392 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 3 ms
4,572 KB
testcase_03 AC 6 ms
5,784 KB
testcase_04 AC 30 ms
16,900 KB
testcase_05 AC 30 ms
17,056 KB
testcase_06 AC 30 ms
17,856 KB
testcase_07 AC 29 ms
18,572 KB
testcase_08 AC 30 ms
16,912 KB
testcase_09 AC 2 ms
4,476 KB
testcase_10 AC 28 ms
16,140 KB
testcase_11 AC 29 ms
16,048 KB
testcase_12 AC 28 ms
16,064 KB
testcase_13 AC 29 ms
16,152 KB
testcase_14 AC 29 ms
17,368 KB
testcase_15 AC 30 ms
17,232 KB
testcase_16 AC 29 ms
17,540 KB
testcase_17 AC 30 ms
16,960 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 29 ms
17,588 KB
testcase_20 AC 2 ms
4,396 KB
testcase_21 AC 2 ms
4,392 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,388 KB
testcase_24 AC 23 ms
14,684 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,388 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,436 KB
testcase_29 AC 2 ms
4,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = read_line.to_i
a = read_line.split.map(&.to_i64)
b = read_line.split.map(&.to_i64)
sa = a.sum
sb = b.sum
if sa < sb || (n == 2 && sa != sb) || (n > 2 && (sa - sb) % (n - 2) != 0)
  puts "-1"
else
  if n == 2
    puts (a[0] - b[0]).abs
  else
    c = (sa - sb) // (n - 2)
    a = a.map { |v| v - c }
    puts (0...n).any? { |i| a[i] > b[i] || (b[i] - a[i]) % 2 != 0 } ? -1 : c
  end
end
0