結果

問題 No.6 使いものにならないハッシュ
ユーザー myuonmyuon
提出日時 2015-03-09 09:51:37
言語 Haskell
(9.8.2)
結果
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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1,091 ms
11,008 KB
testcase_03 AC 36 ms
6,912 KB
testcase_04 AC 48 ms
8,576 KB
testcase_05 AC 95 ms
8,832 KB
testcase_06 AC 238 ms
9,600 KB
testcase_07 AC 86 ms
8,704 KB
testcase_08 AC 165 ms
9,472 KB
testcase_09 AC 49 ms
8,448 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 52 ms
7,680 KB
testcase_12 AC 358 ms
10,112 KB
testcase_13 AC 35 ms
8,576 KB
testcase_14 AC 48 ms
8,448 KB
testcase_15 AC 231 ms
9,728 KB
testcase_16 AC 99 ms
9,088 KB
testcase_17 AC 340 ms
9,728 KB
testcase_18 AC 852 ms
10,880 KB
testcase_19 AC 317 ms
9,728 KB
testcase_20 AC 290 ms
9,856 KB
testcase_21 AC 18 ms
6,016 KB
testcase_22 AC 294 ms
9,600 KB
testcase_23 AC 321 ms
9,856 KB
testcase_24 AC 277 ms
9,856 KB
testcase_25 AC 123 ms
9,088 KB
testcase_26 AC 421 ms
10,112 KB
testcase_27 AC 228 ms
9,984 KB
testcase_28 AC 124 ms
8,704 KB
testcase_29 AC 597 ms
10,496 KB
testcase_30 AC 457 ms
10,240 KB
testcase_31 AC 300 ms
9,856 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: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

ソースコード

diff #

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'
0