結果

問題 No.1120 Strange Teacher
ユーザー simansiman
提出日時 2021-12-07 05:28:54
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 426 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 11,168 KB
実行使用メモリ 31,744 KB
最終ジャッジ日時 2023-09-21 16:34:14
合計ジャッジ時間 9,061 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,076 KB
testcase_01 AC 82 ms
15,068 KB
testcase_02 AC 84 ms
15,272 KB
testcase_03 AC 91 ms
15,608 KB
testcase_04 AC 187 ms
31,536 KB
testcase_05 AC 186 ms
31,472 KB
testcase_06 AC 187 ms
31,536 KB
testcase_07 AC 187 ms
31,732 KB
testcase_08 AC 197 ms
31,680 KB
testcase_09 AC 83 ms
15,188 KB
testcase_10 AC 157 ms
28,308 KB
testcase_11 AC 156 ms
28,284 KB
testcase_12 AC 156 ms
28,268 KB
testcase_13 AC 158 ms
28,276 KB
testcase_14 AC 157 ms
28,080 KB
testcase_15 AC 158 ms
28,208 KB
testcase_16 AC 182 ms
31,632 KB
testcase_17 AC 182 ms
31,724 KB
testcase_18 AC 85 ms
15,128 KB
testcase_19 AC 196 ms
31,744 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 83 ms
15,232 KB
testcase_23 AC 83 ms
15,056 KB
testcase_24 AC 189 ms
31,072 KB
testcase_25 AC 83 ms
15,052 KB
testcase_26 AC 84 ms
15,072 KB
testcase_27 AC 83 ms
15,076 KB
testcase_28 AC 84 ms
15,056 KB
testcase_29 AC 82 ms
15,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

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
0