結果

問題 No.12 限定された素数
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2016-02-20 09:24:27
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 11,888 KB
実行使用メモリ 28,388 KB
最終ジャッジ日時 2023-10-23 18:39:48
合計ジャッジ時間 91,374 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 3,215 ms
28,308 KB
testcase_02 AC 3,118 ms
28,308 KB
testcase_03 AC 3,243 ms
28,388 KB
testcase_04 WA -
testcase_05 AC 3,226 ms
28,308 KB
testcase_06 AC 3,216 ms
28,308 KB
testcase_07 AC 3,238 ms
28,308 KB
testcase_08 WA -
testcase_09 AC 3,196 ms
28,308 KB
testcase_10 WA -
testcase_11 AC 3,266 ms
28,308 KB
testcase_12 AC 3,242 ms
28,308 KB
testcase_13 AC 3,225 ms
28,308 KB
testcase_14 WA -
testcase_15 AC 3,394 ms
28,308 KB
testcase_16 AC 3,489 ms
28,360 KB
testcase_17 AC 3,126 ms
28,308 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"
require "set"
prime_max = 5000000

gets
set = gets.split.map(&:to_i).to_set

ok = Set.new
start = 1
remain = set
exist_flag = false
complete_flag = false

Prime.each(prime_max) do |prime|
  nums = prime.to_s.each_char.map(&:to_i).to_set
  if set.superset?(nums)
    unless complete_flag
      exist_flag = true
      remain -= nums
      if remain.empty?
        complete_flag = true
      end
    end
  else
    if exist_flag
      if complete_flag
        ok << prime - 1 - start
      end
      remain = set
    end
    start = prime + 1
  end
end
if complete_flag
  ok << prime_max - start
end
if ok.empty?
  puts(-1)
else
  puts(ok.max)
end
0