結果

問題 No.6 使いものにならないハッシュ
ユーザー aimyaimy
提出日時 2017-05-09 12:42:40
言語 Haskell
(9.8.2)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 710 bytes
コンパイル時間 4,745 ms
コンパイル使用メモリ 160,064 KB
実行使用メモリ 12,520 KB
最終ジャッジ日時 2023-10-14 23:05:00
合計ジャッジ時間 7,035 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,104 KB
testcase_01 AC 2 ms
7,092 KB
testcase_02 AC 52 ms
11,984 KB
testcase_03 AC 12 ms
10,732 KB
testcase_04 AC 22 ms
11,496 KB
testcase_05 AC 22 ms
11,376 KB
testcase_06 AC 32 ms
12,076 KB
testcase_07 AC 32 ms
11,588 KB
testcase_08 AC 32 ms
12,016 KB
testcase_09 AC 42 ms
11,792 KB
testcase_10 AC 2 ms
6,972 KB
testcase_11 AC 12 ms
11,344 KB
testcase_12 AC 32 ms
11,724 KB
testcase_13 AC 42 ms
11,784 KB
testcase_14 AC 42 ms
11,808 KB
testcase_15 AC 32 ms
11,784 KB
testcase_16 AC 42 ms
12,520 KB
testcase_17 AC 42 ms
12,176 KB
testcase_18 AC 43 ms
11,924 KB
testcase_19 AC 41 ms
12,132 KB
testcase_20 AC 42 ms
12,116 KB
testcase_21 AC 6 ms
9,456 KB
testcase_22 AC 42 ms
12,056 KB
testcase_23 AC 32 ms
11,772 KB
testcase_24 AC 42 ms
12,060 KB
testcase_25 AC 31 ms
12,088 KB
testcase_26 AC 42 ms
12,152 KB
testcase_27 AC 42 ms
12,092 KB
testcase_28 AC 22 ms
11,772 KB
testcase_29 AC 42 ms
11,940 KB
testcase_30 AC 41 ms
11,876 KB
testcase_31 AC 42 ms
12,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Char

primes = 2:3:[x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
 where isPrime n = null [i | i<-takeWhile (\x -> x^2 <= n) primes, mod n i == 0]

main = do
 [k,n] <- map read . words <$> getContents
 let ps = dropWhile (<k) (takeWhile (<=n) primes)
 print (ulhash [] (map hash ps))

ulhash acc [] = head acc
ulhash acc hps = ulhash (maxhash acc (dtp [] hps)) (tail hps)

hash p = (until (<10) (sum . map digitToInt . show) p, p) 

dtp acc [] = map snd (reverse acc)
dtp acc ((h,p):hps)
 | lookup h acc /= Nothing = map snd (reverse acc)
 | otherwise = dtp ((h,p):acc) hps

maxhash hps1 hps2
 | length hps1 > length hps2 = hps1
 | length hps1 < length hps2 = hps2
 | otherwise = max hps1 hps2
0