結果
| 問題 | No.443 GCD of Permutation | 
| コンテスト | |
| ユーザー |  atuk721 | 
| 提出日時 | 2017-02-14 05:35:06 | 
| 言語 | Haskell (9.10.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 1,000 ms | 
| コード長 | 650 bytes | 
| コンパイル時間 | 4,877 ms | 
| コンパイル使用メモリ | 175,744 KB | 
| 実行使用メモリ | 8,192 KB | 
| 最終ジャッジ日時 | 2024-10-14 00:06:27 | 
| 合計ジャッジ時間 | 3,703 ms | 
| ジャッジサーバーID (参考情報) | judge3 / 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 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 <- [0..9], y <- [0..9], x > y]
        ns' = filter (\(x, y) -> x `elem` ns && y `elem` ns) pattern
            
            
            
        