結果

問題 No.1120 Strange Teacher
ユーザー tomeruntomerun
提出日時 2020-07-26 15:57:54
言語 Crystal
(1.11.2)
結果
AC  
実行時間 30 ms / 1,000 ms
コード長 390 bytes
コンパイル時間 17,483 ms
コンパイル使用メモリ 255,728 KB
実行使用メモリ 18,172 KB
最終ジャッジ日時 2023-09-13 11:27:22
合計ジャッジ時間 18,580 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,404 KB
testcase_01 AC 2 ms
4,404 KB
testcase_02 AC 3 ms
4,508 KB
testcase_03 AC 5 ms
5,980 KB
testcase_04 AC 28 ms
17,344 KB
testcase_05 AC 30 ms
16,900 KB
testcase_06 AC 27 ms
17,824 KB
testcase_07 AC 28 ms
16,992 KB
testcase_08 AC 28 ms
17,556 KB
testcase_09 AC 2 ms
4,404 KB
testcase_10 AC 27 ms
16,132 KB
testcase_11 AC 26 ms
16,136 KB
testcase_12 AC 28 ms
17,480 KB
testcase_13 AC 27 ms
16,140 KB
testcase_14 AC 27 ms
16,132 KB
testcase_15 AC 29 ms
16,260 KB
testcase_16 AC 28 ms
18,172 KB
testcase_17 AC 27 ms
17,660 KB
testcase_18 AC 2 ms
4,456 KB
testcase_19 AC 28 ms
17,816 KB
testcase_20 AC 2 ms
4,448 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,392 KB
testcase_23 AC 2 ms
4,472 KB
testcase_24 AC 24 ms
14,636 KB
testcase_25 AC 2 ms
4,396 KB
testcase_26 AC 3 ms
4,504 KB
testcase_27 AC 2 ms
4,476 KB
testcase_28 AC 3 ms
4,468 KB
testcase_29 AC 3 ms
4,388 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