結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  aimy | 
| 提出日時 | 2017-05-09 12:42:40 | 
| 言語 | Haskell (9.10.1) | 
| 結果 | 
                                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 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
コンパイルメッセージ
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
