結果

問題 No.1120 Strange Teacher
ユーザー simansiman
提出日時 2021-12-07 05:29:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 428 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 11,516 KB
実行使用メモリ 31,816 KB
最終ジャッジ日時 2023-09-21 16:34:21
合計ジャッジ時間 5,678 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,032 KB
testcase_01 AC 81 ms
15,052 KB
testcase_02 AC 83 ms
15,112 KB
testcase_03 AC 89 ms
15,720 KB
testcase_04 AC 184 ms
31,548 KB
testcase_05 AC 187 ms
31,608 KB
testcase_06 AC 188 ms
31,480 KB
testcase_07 AC 188 ms
31,564 KB
testcase_08 AC 188 ms
31,604 KB
testcase_09 AC 80 ms
15,244 KB
testcase_10 AC 155 ms
28,144 KB
testcase_11 AC 157 ms
28,088 KB
testcase_12 AC 155 ms
28,128 KB
testcase_13 AC 156 ms
28,176 KB
testcase_14 AC 156 ms
28,068 KB
testcase_15 AC 155 ms
28,260 KB
testcase_16 AC 180 ms
31,724 KB
testcase_17 AC 181 ms
31,436 KB
testcase_18 AC 82 ms
14,948 KB
testcase_19 AC 190 ms
31,816 KB
testcase_20 AC 81 ms
15,156 KB
testcase_21 AC 81 ms
15,140 KB
testcase_22 AC 81 ms
15,172 KB
testcase_23 AC 80 ms
15,144 KB
testcase_24 AC 187 ms
31,392 KB
testcase_25 AC 82 ms
15,144 KB
testcase_26 AC 81 ms
15,236 KB
testcase_27 AC 82 ms
15,120 KB
testcase_28 AC 81 ms
15,184 KB
testcase_29 AC 83 ms
15,140 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 (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
0