結果
問題 | No.1120 Strange Teacher |
ユーザー | siman |
提出日時 | 2021-12-07 05:29:45 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 159 ms / 1,000 ms |
コード長 | 428 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 31,616 KB |
最終ジャッジ日時 | 2024-07-07 10:17:02 |
合計ジャッジ時間 | 4,970 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
Main.rb:11: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:21: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
N = gets.to_i A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) S_A = A.sum S_B = B.sum if N == 2 if S_A == S_B puts (A[0] - B[0]).abs else puts -1 end else if S_A >= S_B && (S_A - S_B) % (N - 2) == 0 v = (S_A - S_B) / (N - 2) P = A.zip(B).map { |a, b| b - (a - v) } if P.all? { |x| x >= 0 && x.even? } && P.sum == 2 * v puts v else puts -1 end else puts -1 end end