結果
| 問題 |
No.6 使いものにならないハッシュ
|
| ユーザー |
|
| 提出日時 | 2015-03-09 09:51:37 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 1,091 ms / 5,000 ms |
| コード長 | 826 bytes |
| コンパイル時間 | 6,174 ms |
| コンパイル使用メモリ | 170,428 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-09-16 16:25:13 |
| 合計ジャッジ時間 | 14,650 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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:10:18: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Data.List, 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."
|
10 | solve ns = fst $ head $ iter' $ zip ns $ fmap hash ns where
| ^^^^
Main.hs:15:63: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Data.List, 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."
|
15 | iter' xs = maximumBy (comparing (\xs -> (length xs, fst $ head xs))) [flip iter [] $ drop p xs|p<-[0..length xs]]
| ^^^^
[2 of 2] Linking a.out
ソースコード
import Control.Applicative
import Data.List
import Data.Ord
import Data.Char
sieve' = 2:3:[x|i<-[1..],j<-[-1,1], let x = 6*i+j, isPrime x] where
isPrime n = null [p|p<-takeWhile (\x -> x*x <=n) sieve', rem n p == 0]
solve :: [Int] -> Int
solve ns = fst $ head $ iter' $ zip ns $ fmap hash ns where
hash x = let x' = sum . fmap digitToInt . show $ x in
if length (show x') == 1 then x'
else hash x'
iter' xs = maximumBy (comparing (\xs -> (length xs, fst $ head xs))) [flip iter [] $ drop p xs|p<-[0..length xs]]
iter [] acc = acc
iter (x:xs) acc = if snd x `elem` fmap snd acc then acc else iter xs (x:acc)
main = do
k <- (read :: String -> Int) <$> getLine
n <- (read :: String -> Int) <$> getLine
print $ solve $ reverse $ dropWhile (<k) $ takeWhile (<=n) $ sieve'