結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2017-02-14 05:32:28 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 650 bytes |
コンパイル時間 | 7,857 ms |
コンパイル使用メモリ | 173,440 KB |
実行使用メモリ | 8,448 KB |
最終ジャッジ日時 | 2024-12-29 21:02:41 |
合計ジャッジ時間 | 4,437 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 21 WA * 7 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import qualified Data.Char as C import qualified Data.List as L main :: IO () main = do n <- getLine let ns = map C.digitToInt . L.nub $ n result = if length ns == 1 then read n else proc (read n) $ createPattern ns print result proc :: Integer -> [(Integer, Integer)] -> Integer proc n ns = foldr gcd n ns' where ns' = map (\(a, b) -> 9 * (a - b)) ns createPattern :: [Int] -> [(Integer, Integer)] createPattern ns = map (\(x, y) -> (toInteger x, toInteger y)) ns' where pattern = [(x, y) | x <- [1..9], y <- [1..9], x > y] ns' = filter (\(x, y) -> x `elem` ns && y `elem` ns) pattern