結果

問題 No.1884 Sequence
ユーザー simansiman
提出日時 2022-03-27 09:46:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 43,076 KB
最終ジャッジ日時 2024-04-23 22:38:14
合計ジャッジ時間 11,644 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
12,288 KB
testcase_01 AC 90 ms
12,160 KB
testcase_02 AC 90 ms
12,160 KB
testcase_03 AC 90 ms
12,416 KB
testcase_04 AC 90 ms
12,160 KB
testcase_05 AC 88 ms
12,288 KB
testcase_06 AC 88 ms
12,160 KB
testcase_07 AC 88 ms
12,288 KB
testcase_08 AC 88 ms
12,416 KB
testcase_09 AC 90 ms
12,160 KB
testcase_10 AC 361 ms
41,500 KB
testcase_11 AC 363 ms
41,356 KB
testcase_12 AC 209 ms
25,600 KB
testcase_13 AC 224 ms
26,880 KB
testcase_14 AC 210 ms
25,344 KB
testcase_15 AC 300 ms
39,040 KB
testcase_16 AC 351 ms
42,900 KB
testcase_17 AC 262 ms
34,816 KB
testcase_18 AC 283 ms
39,168 KB
testcase_19 AC 256 ms
36,096 KB
testcase_20 AC 286 ms
36,864 KB
testcase_21 AC 264 ms
33,408 KB
testcase_22 AC 293 ms
37,632 KB
testcase_23 AC 350 ms
42,904 KB
testcase_24 AC 355 ms
43,076 KB
testcase_25 AC 332 ms
41,412 KB
testcase_26 AC 324 ms
41,356 KB
testcase_27 AC 185 ms
29,056 KB
testcase_28 AC 186 ms
28,800 KB
testcase_29 AC 185 ms
28,800 KB
testcase_30 AC 243 ms
30,336 KB
testcase_31 AC 204 ms
32,896 KB
testcase_32 AC 272 ms
40,868 KB
testcase_33 AC 208 ms
33,024 KB
testcase_34 AC 210 ms
33,280 KB
testcase_35 AC 198 ms
29,184 KB
testcase_36 AC 208 ms
30,464 KB
testcase_37 AC 227 ms
35,328 KB
testcase_38 AC 222 ms
34,048 KB
testcase_39 AC 202 ms
28,928 KB
testcase_40 AC 202 ms
29,184 KB
testcase_41 AC 311 ms
38,320 KB
testcase_42 AC 331 ms
38,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i).sort

B = A.select { |x| x > 0 }

if B.uniq.size == 1
  puts 'Yes'
  exit
elsif B.size != B.uniq.size
  puts 'No'
  exit
end

zc = A.count(0)
range = B.each_cons(2).map { |a, b| b - a }.inject(&:gcd)

stack = []

until B.empty?
  b = B.shift
  stack << b

  if stack.size >= 2
    if stack[-1] - stack[-2] > range
      if zc > 0
        c = stack.pop
        stack << stack.last + range
        B.unshift(c)
        zc -= 1
      else
        puts 'No'
        exit
      end
    end
  end
end

puts 'Yes'
0