結果

問題 No.12 限定された素数
ユーザー letrangerjpletrangerjp
提出日時 2017-05-15 01:01:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,516 ms / 5,000 ms
コード長 455 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 11,280 KB
実行使用メモリ 27,780 KB
最終ジャッジ日時 2023-08-16 00:38:35
合計ジャッジ時間 54,880 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,834 ms
27,500 KB
testcase_01 AC 1,954 ms
27,584 KB
testcase_02 AC 1,875 ms
27,516 KB
testcase_03 AC 91 ms
15,100 KB
testcase_04 AC 1,863 ms
27,640 KB
testcase_05 AC 2,025 ms
27,612 KB
testcase_06 AC 2,148 ms
27,644 KB
testcase_07 AC 2,215 ms
27,488 KB
testcase_08 AC 2,000 ms
27,432 KB
testcase_09 AC 1,938 ms
27,640 KB
testcase_10 AC 2,018 ms
27,444 KB
testcase_11 AC 2,516 ms
27,688 KB
testcase_12 AC 2,237 ms
27,448 KB
testcase_13 AC 2,074 ms
27,392 KB
testcase_14 AC 1,977 ms
27,512 KB
testcase_15 AC 2,088 ms
27,496 KB
testcase_16 AC 2,272 ms
27,660 KB
testcase_17 AC 1,841 ms
27,508 KB
testcase_18 AC 1,845 ms
27,504 KB
testcase_19 AC 1,835 ms
27,700 KB
testcase_20 AC 1,917 ms
27,500 KB
testcase_21 AC 1,979 ms
27,504 KB
testcase_22 AC 1,849 ms
27,508 KB
testcase_23 AC 1,860 ms
27,780 KB
testcase_24 AC 1,837 ms
27,636 KB
testcase_25 AC 2,037 ms
27,328 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"

def f(a)
  max = -1
  start = 1
  last = Prime.each(PRIME_MAX).inject([]){|curr, pr|
    pr_a = pr.to_s.chars

    if !((curr | pr_a) - a).empty?
      max = [max, pr - start - 1].max if curr.size == a.size
      start = pr + 1
      []
    else
      curr | pr_a
    end
  }
  max = [max, PRIME_MAX - start].max if last.size == a.size
  max
end

PRIME_MAX = 5_000_000
N = gets.to_i
A = gets.split.take(N)

p N == 10 ? PRIME_MAX-1 : f(A)
0