結果

問題 No.6 使いものにならないハッシュ
ユーザー myuonmyuon
提出日時 2015-03-09 09:51:37
言語 Haskell
(9.8.2)
結果
AC  
実行時間 872 ms / 5,000 ms
コード長 826 bytes
コンパイル時間 5,332 ms
コンパイル使用メモリ 161,864 KB
実行使用メモリ 14,568 KB
最終ジャッジ日時 2023-10-14 22:50:26
合計ジャッジ時間 13,549 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,080 KB
testcase_01 AC 2 ms
7,092 KB
testcase_02 AC 872 ms
14,568 KB
testcase_03 AC 42 ms
10,344 KB
testcase_04 AC 52 ms
11,628 KB
testcase_05 AC 102 ms
11,876 KB
testcase_06 AC 212 ms
12,588 KB
testcase_07 AC 92 ms
11,864 KB
testcase_08 AC 172 ms
12,496 KB
testcase_09 AC 52 ms
11,732 KB
testcase_10 AC 2 ms
6,984 KB
testcase_11 AC 62 ms
10,908 KB
testcase_12 AC 352 ms
13,052 KB
testcase_13 AC 42 ms
11,644 KB
testcase_14 AC 52 ms
11,776 KB
testcase_15 AC 242 ms
12,756 KB
testcase_16 AC 102 ms
12,096 KB
testcase_17 AC 342 ms
13,064 KB
testcase_18 AC 762 ms
14,328 KB
testcase_19 AC 322 ms
12,972 KB
testcase_20 AC 283 ms
13,008 KB
testcase_21 AC 22 ms
9,148 KB
testcase_22 AC 292 ms
12,940 KB
testcase_23 AC 313 ms
12,992 KB
testcase_24 AC 282 ms
12,936 KB
testcase_25 AC 122 ms
12,260 KB
testcase_26 AC 442 ms
13,456 KB
testcase_27 AC 232 ms
12,932 KB
testcase_28 AC 132 ms
12,612 KB
testcase_29 AC 532 ms
13,584 KB
testcase_30 AC 422 ms
13,204 KB
testcase_31 AC 302 ms
12,944 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 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