結果

問題 No.6 使いものにならないハッシュ
ユーザー maimai
提出日時 2017-07-07 22:39:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 721 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 11,592 KB
実行使用メモリ 16,524 KB
最終ジャッジ日時 2023-10-14 23:07:21
合計ジャッジ時間 5,256 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,364 KB
testcase_01 AC 89 ms
15,412 KB
testcase_02 AC 138 ms
16,312 KB
testcase_03 AC 100 ms
15,488 KB
testcase_04 AC 112 ms
15,672 KB
testcase_05 AC 109 ms
15,776 KB
testcase_06 AC 131 ms
16,244 KB
testcase_07 AC 126 ms
16,456 KB
testcase_08 AC 129 ms
16,288 KB
testcase_09 AC 123 ms
16,448 KB
testcase_10 AC 86 ms
15,428 KB
testcase_11 AC 99 ms
15,460 KB
testcase_12 AC 131 ms
16,300 KB
testcase_13 AC 122 ms
16,352 KB
testcase_14 AC 123 ms
16,272 KB
testcase_15 AC 128 ms
16,452 KB
testcase_16 AC 127 ms
16,412 KB
testcase_17 AC 134 ms
16,436 KB
testcase_18 AC 139 ms
16,400 KB
testcase_19 AC 132 ms
16,292 KB
testcase_20 AC 130 ms
16,220 KB
testcase_21 AC 93 ms
15,520 KB
testcase_22 AC 132 ms
16,304 KB
testcase_23 AC 132 ms
16,408 KB
testcase_24 AC 133 ms
16,524 KB
testcase_25 AC 129 ms
16,416 KB
testcase_26 AC 135 ms
16,408 KB
testcase_27 AC 131 ms
16,220 KB
testcase_28 AC 111 ms
15,844 KB
testcase_29 AC 135 ms
16,316 KB
testcase_30 AC 134 ms
16,388 KB
testcase_31 AC 132 ms
16,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i); end
def scan; gets.to_i; end


require 'prime'


k,n = [gets,gets].map(&:to_i)

# 素数列挙
prime_generator = Prime::EratosthenesGenerator.new
primes = []
begin ; primes << prime_generator.next ; end while primes[-1]<=n

primes.pop if primes[-1]>n

def ash(u)
    u<10 ? u : ash(ash(u/10)+u%10)
end

ptr = 0

while primes[ptr] < k
    ptr+=1
end

li = Array.new(10)
q = []

best = 0
best_arr = nil

while ptr < primes.size
    v = primes[ptr]
    h = ash(v)
    while li[h]
        r = q.shift()
        li[r] = nil
    end
    li[h] = v
    q.push(h)
    
    if best <= q.size
        best = q.size
        best_arr = q.map{|i| li[i]}
    end
        
    ptr+=1
end

p best_arr[0]
0