結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2017-02-14 05:46:08 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 6 ms / 1,000 ms |
コード長 | 574 bytes |
コンパイル時間 | 11,806 ms |
コンパイル使用メモリ | 175,744 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-10-14 00:07:02 |
合計ジャッジ時間 | 3,202 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
コンパイルメッセージ
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 (toInteger . C.digitToInt) . L.nub $ n print $ if length ns == 1 then read n else proc (read n) $ createPattern ns proc :: Integer -> [(Integer, Integer)] -> Integer proc n ns = foldr gcd n ns' where ns' = map (\(a, b) -> 9 * (a - b)) ns createPattern :: [Integer] -> [(Integer, Integer)] createPattern ns = filter (\(x, y) -> x `elem` ns && y `elem` ns) pattern where pattern = [(x, y) | x <- [0..9], y <- [0..9], x > y]