結果

問題 No.443 GCD of Permutation
ユーザー atuk721atuk721
提出日時 2017-02-14 05:00:26
言語 Haskell
(9.8.2)
結果
MLE  
実行時間 -
コード長 584 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 166,164 KB
実行使用メモリ 747,168 KB
最終ジャッジ日時 2023-08-28 16:27:15
合計ジャッジ時間 5,821 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
14,524 KB
testcase_01 AC 2 ms
7,256 KB
testcase_02 AC 2 ms
7,364 KB
testcase_03 AC 2 ms
7,412 KB
testcase_04 AC 2 ms
7,404 KB
testcase_05 AC 3 ms
7,020 KB
testcase_06 AC 2 ms
7,368 KB
testcase_07 AC 3 ms
7,788 KB
testcase_08 AC 2 ms
7,252 KB
testcase_09 AC 3 ms
7,268 KB
testcase_10 AC 3 ms
7,260 KB
testcase_11 AC 2 ms
7,264 KB
testcase_12 AC 3 ms
7,352 KB
testcase_13 AC 3 ms
7,344 KB
testcase_14 AC 12 ms
11,896 KB
testcase_15 AC 4 ms
8,824 KB
testcase_16 AC 3 ms
8,000 KB
testcase_17 AC 3 ms
8,208 KB
testcase_18 AC 7 ms
11,480 KB
testcase_19 MLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = do
  n <- getLine
  let ns = L.permutations . L.nub $ n
      result = if length ns == 1
                  then read n
                  else proc (read n) $ convert ns

  print result

proc :: Integer -> [(Integer, Integer)] -> Integer
proc n ns = foldr gcd n ns''
  where ns' = L.nub . filter (\(x, y) -> x > y) $ ns
        ns'' = map (\(a, b) -> 9 * (a - b)) ns'

convert :: [String] -> [(Integer, Integer)]
convert = map (\(x:y:zs) -> (toInteger $ C.digitToInt x, toInteger $ C.digitToInt y))
0