結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
12,288 KB
testcase_01 AC 111 ms
12,288 KB
testcase_02 AC 170 ms
13,312 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 107 ms
12,416 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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