結果

問題 No.1120 Strange Teacher
ユーザー tomeruntomerun
提出日時 2020-07-22 21:42:39
言語 Crystal
(1.11.2)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 388 bytes
コンパイル時間 19,168 ms
コンパイル使用メモリ 254,404 KB
実行使用メモリ 17,860 KB
最終ジャッジ日時 2023-09-13 11:22:03
合計ジャッジ時間 22,703 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,456 KB
testcase_01 AC 2 ms
4,492 KB
testcase_02 AC 3 ms
4,752 KB
testcase_03 AC 5 ms
5,852 KB
testcase_04 AC 30 ms
17,492 KB
testcase_05 AC 30 ms
16,832 KB
testcase_06 AC 31 ms
16,828 KB
testcase_07 AC 30 ms
17,512 KB
testcase_08 AC 29 ms
17,860 KB
testcase_09 AC 3 ms
4,548 KB
testcase_10 AC 29 ms
17,568 KB
testcase_11 AC 29 ms
16,200 KB
testcase_12 AC 29 ms
17,536 KB
testcase_13 AC 30 ms
17,660 KB
testcase_14 AC 29 ms
16,120 KB
testcase_15 AC 30 ms
16,136 KB
testcase_16 AC 29 ms
17,724 KB
testcase_17 AC 30 ms
16,988 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 31 ms
16,920 KB
testcase_20 AC 3 ms
4,388 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 25 ms
14,688 KB
testcase_25 AC 2 ms
4,432 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,452 KB
testcase_29 AC 2 ms
4,376 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