結果

問題 No.1120 Strange Teacher
ユーザー tomerun
提出日時 2020-07-22 21:44:35
言語 Ruby
(3.4.1)
結果
AC  
実行時間 170 ms / 1,000 ms
コード長 380 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-06-22 15:06:27
合計ジャッジ時間 5,010 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
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