結果

問題 No.1120 Strange Teacher
ユーザー tomeruntomerun
提出日時 2020-07-22 21:44:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 178 ms / 1,000 ms
コード長 380 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 29,128 KB
最終ジャッジ日時 2023-09-04 16:59:51
合計ジャッジ時間 5,780 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,272 KB
testcase_01 AC 82 ms
15,016 KB
testcase_02 AC 84 ms
15,096 KB
testcase_03 AC 91 ms
15,696 KB
testcase_04 AC 177 ms
28,868 KB
testcase_05 AC 177 ms
29,092 KB
testcase_06 AC 177 ms
28,832 KB
testcase_07 AC 175 ms
28,864 KB
testcase_08 AC 176 ms
28,864 KB
testcase_09 AC 81 ms
15,148 KB
testcase_10 AC 158 ms
28,252 KB
testcase_11 AC 158 ms
28,144 KB
testcase_12 AC 155 ms
28,160 KB
testcase_13 AC 155 ms
28,232 KB
testcase_14 AC 156 ms
28,116 KB
testcase_15 AC 158 ms
28,276 KB
testcase_16 AC 163 ms
28,956 KB
testcase_17 AC 161 ms
29,016 KB
testcase_18 AC 81 ms
15,124 KB
testcase_19 AC 178 ms
29,128 KB
testcase_20 AC 80 ms
15,148 KB
testcase_21 AC 82 ms
15,276 KB
testcase_22 AC 82 ms
15,184 KB
testcase_23 AC 82 ms
15,272 KB
testcase_24 AC 175 ms
28,504 KB
testcase_25 AC 82 ms
15,092 KB
testcase_26 AC 81 ms
15,100 KB
testcase_27 AC 81 ms
15,248 KB
testcase_28 AC 82 ms
15,152 KB
testcase_29 AC 82 ms
15,084 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:7: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

n = readline.to_i
a = readline.split.map(&:to_i)
b = readline.split.map(&:to_i)
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