結果

問題 No.12 限定された素数
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2016-02-20 09:05:44
言語 Ruby
(3.2.2)
結果
AC  
実行時間 3,710 ms / 5,000 ms
コード長 509 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 11,476 KB
実行使用メモリ 28,408 KB
最終ジャッジ日時 2023-08-15 23:24:10
合計ジャッジ時間 91,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,156 ms
27,572 KB
testcase_01 AC 3,213 ms
27,604 KB
testcase_02 AC 3,157 ms
27,328 KB
testcase_03 AC 3,710 ms
28,408 KB
testcase_04 AC 3,183 ms
27,560 KB
testcase_05 AC 3,237 ms
27,616 KB
testcase_06 AC 3,262 ms
27,756 KB
testcase_07 AC 3,371 ms
27,732 KB
testcase_08 AC 3,213 ms
27,656 KB
testcase_09 AC 3,215 ms
27,564 KB
testcase_10 AC 3,274 ms
27,460 KB
testcase_11 AC 3,601 ms
27,680 KB
testcase_12 AC 3,407 ms
27,636 KB
testcase_13 AC 3,436 ms
27,700 KB
testcase_14 AC 3,264 ms
27,588 KB
testcase_15 AC 3,314 ms
27,784 KB
testcase_16 AC 3,552 ms
27,664 KB
testcase_17 AC 3,226 ms
27,576 KB
testcase_18 AC 3,201 ms
27,792 KB
testcase_19 AC 3,183 ms
27,560 KB
testcase_20 AC 3,214 ms
27,872 KB
testcase_21 AC 3,213 ms
27,680 KB
testcase_22 AC 3,231 ms
27,660 KB
testcase_23 AC 3,278 ms
27,784 KB
testcase_24 AC 3,233 ms
27,392 KB
testcase_25 AC 3,313 ms
27,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"
require "set"
prime_max = 5000000

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

ok_set = Set.new
start = 1
now_set = Set.new

Prime.each(prime_max) do |prime|
  num_set = prime.to_s.each_char.map(&:to_i).uniq.to_set
  if set.superset?(num_set)
    now_set += num_set
  else
    if set == now_set
      ok_set << prime - 1 - start
    end
    start = prime + 1
    now_set.clear
  end
end
if set == now_set
  ok_set << prime_max - start
end
if ok_set.empty?
  puts(-1)
else
  puts(ok_set.max)
end
0