結果

問題 No.6 使いものにならないハッシュ
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-07-29 14:25:51
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 16,624 KB
最終ジャッジ日時 2023-09-24 21:42:04
合計ジャッジ時間 7,863 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 95 ms
15,192 KB
testcase_02 AC 225 ms
16,328 KB
testcase_03 AC 118 ms
15,416 KB
testcase_04 AC 131 ms
15,804 KB
testcase_05 AC 143 ms
15,752 KB
testcase_06 WA -
testcase_07 AC 153 ms
16,000 KB
testcase_08 AC 170 ms
16,092 KB
testcase_09 AC 143 ms
16,072 KB
testcase_10 AC 95 ms
15,340 KB
testcase_11 AC 122 ms
15,484 KB
testcase_12 AC 192 ms
16,356 KB
testcase_13 AC 139 ms
15,920 KB
testcase_14 AC 144 ms
16,096 KB
testcase_15 AC 180 ms
16,624 KB
testcase_16 WA -
testcase_17 AC 195 ms
15,912 KB
testcase_18 AC 221 ms
16,160 KB
testcase_19 AC 189 ms
16,024 KB
testcase_20 AC 184 ms
16,348 KB
testcase_21 AC 111 ms
15,480 KB
testcase_22 WA -
testcase_23 AC 189 ms
16,588 KB
testcase_24 AC 186 ms
15,972 KB
testcase_25 AC 160 ms
15,956 KB
testcase_26 AC 202 ms
16,264 KB
testcase_27 WA -
testcase_28 AC 150 ms
15,652 KB
testcase_29 AC 204 ms
16,360 KB
testcase_30 AC 199 ms
16,432 KB
testcase_31 AC 190 ms
15,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !
require 'prime'

def xxx_hash(n)
    if n < 10
        n
    else
        xxx_hash(n.to_s.chars.map(&:to_i).inject(0) {|s,v| s+v})
    end
end

l,h = 2.times.map { gets.to_i }
primes = Prime.each(h).select {|prime|  prime >= l}
puts primes.each_with_index.each_with_object({primes: [], hashes: [], max: 0, head: 0}) {|(v,i),s|
    hash = xxx_hash(v)
    
    if s[:hashes].include?(hash)
        offset = s[:hashes].index(hash)
        s[:hashes] = s[:hashes].drop(offset + 1)
        s[:primes] = s[:primes].drop(offset + 1)
        s[:hashes].push(hash)
        s[:primes].push(v)
    else
        s[:primes].push(v)
        s[:hashes].push(hash)
        
        if s[:hashes].size >= s[:max]
            s[:max] = s[:hashes].size
            s[:head] = s[:primes].first
        end
        
    end
    
}[:head]
0