結果
問題 | No.6 使いものにならないハッシュ |
ユーザー | aimy |
提出日時 | 2017-05-09 12:42:40 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 44 ms / 5,000 ms |
コード長 | 710 bytes |
コンパイル時間 | 7,953 ms |
コンパイル使用メモリ | 181,144 KB |
実行使用メモリ | 9,088 KB |
最終ジャッジ日時 | 2024-09-16 16:38:44 |
合計ジャッジ時間 | 7,083 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 44 ms
8,704 KB |
testcase_03 | AC | 8 ms
7,552 KB |
testcase_04 | AC | 15 ms
8,192 KB |
testcase_05 | AC | 13 ms
8,192 KB |
testcase_06 | AC | 28 ms
8,704 KB |
testcase_07 | AC | 25 ms
8,320 KB |
testcase_08 | AC | 29 ms
8,704 KB |
testcase_09 | AC | 36 ms
8,448 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 9 ms
8,064 KB |
testcase_12 | AC | 28 ms
8,448 KB |
testcase_13 | AC | 33 ms
8,448 KB |
testcase_14 | AC | 35 ms
8,320 KB |
testcase_15 | AC | 25 ms
8,320 KB |
testcase_16 | AC | 35 ms
9,088 KB |
testcase_17 | AC | 41 ms
8,832 KB |
testcase_18 | AC | 42 ms
8,576 KB |
testcase_19 | AC | 39 ms
8,832 KB |
testcase_20 | AC | 31 ms
8,704 KB |
testcase_21 | AC | 5 ms
6,016 KB |
testcase_22 | AC | 36 ms
8,704 KB |
testcase_23 | AC | 29 ms
8,448 KB |
testcase_24 | AC | 34 ms
8,704 KB |
testcase_25 | AC | 27 ms
8,832 KB |
testcase_26 | AC | 40 ms
8,704 KB |
testcase_27 | AC | 35 ms
8,960 KB |
testcase_28 | AC | 19 ms
8,448 KB |
testcase_29 | AC | 39 ms
8,704 KB |
testcase_30 | AC | 33 ms
8,576 KB |
testcase_31 | AC | 33 ms
8,576 KB |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:11:17: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 11 | ulhash acc [] = head acc | ^^^^ Main.hs:12:53: warning: [GHC-63394] [-Wx-partial] In the use of ‘tail’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 12 | ulhash acc hps = ulhash (maxhash acc (dtp [] hps)) (tail hps) | ^^^^ [2 of 2] Linking a.out
ソースコード
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