結果

問題 No.6 使いものにならないハッシュ
ユーザー maimai
提出日時 2017-07-07 22:32:39
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-16 01:18:08
合計ジャッジ時間 5,519 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
12,288 KB
testcase_01 AC 104 ms
12,288 KB
testcase_02 AC 163 ms
13,056 KB
testcase_03 AC 121 ms
12,672 KB
testcase_04 AC 127 ms
12,672 KB
testcase_05 AC 129 ms
12,672 KB
testcase_06 AC 150 ms
13,056 KB
testcase_07 AC 142 ms
13,056 KB
testcase_08 AC 151 ms
13,056 KB
testcase_09 AC 145 ms
13,056 KB
testcase_10 AC 107 ms
12,416 KB
testcase_11 WA -
testcase_12 AC 153 ms
13,056 KB
testcase_13 AC 142 ms
13,184 KB
testcase_14 AC 142 ms
13,312 KB
testcase_15 WA -
testcase_16 AC 145 ms
13,184 KB
testcase_17 AC 151 ms
13,184 KB
testcase_18 WA -
testcase_19 AC 155 ms
13,312 KB
testcase_20 AC 149 ms
13,184 KB
testcase_21 AC 112 ms
12,544 KB
testcase_22 AC 151 ms
13,184 KB
testcase_23 AC 152 ms
13,184 KB
testcase_24 AC 149 ms
13,056 KB
testcase_25 AC 145 ms
13,184 KB
testcase_26 AC 154 ms
13,184 KB
testcase_27 AC 150 ms
13,312 KB
testcase_28 WA -
testcase_29 AC 154 ms
13,056 KB
testcase_30 AC 154 ms
13,184 KB
testcase_31 AC 151 ms
13,056 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


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_head = 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_head = li[q[0]]
    end
        
    ptr+=1
end

p best_head
0