結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-12-07 05:28:54 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 426 bytes |
| コンパイル時間 | 128 ms |
| コンパイル使用メモリ | 7,808 KB |
| 実行使用メモリ | 31,360 KB |
| 最終ジャッジ日時 | 2024-07-07 10:16:57 |
| 合計ジャッジ時間 | 6,436 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 2 |
コンパイルメッセージ
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 (S_A - S_B).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
siman