結果

問題 No.326 あみだますたー
ユーザー tottoripapertottoripaper
提出日時 2018-03-09 15:29:38
言語 Haskell
(9.8.2)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 12,637 ms
コンパイル使用メモリ 200,960 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-17 04:30:52
合計ジャッジ時間 12,593 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 5 ms
6,912 KB
testcase_03 AC 42 ms
15,232 KB
testcase_04 AC 8 ms
8,192 KB
testcase_05 AC 4 ms
5,504 KB
testcase_06 AC 27 ms
14,080 KB
testcase_07 AC 14 ms
11,264 KB
testcase_08 AC 10 ms
8,576 KB
testcase_09 AC 41 ms
14,208 KB
testcase_10 AC 35 ms
14,208 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 22 ms
12,928 KB
testcase_13 AC 31 ms
14,080 KB
testcase_14 AC 8 ms
8,448 KB
testcase_15 AC 17 ms
10,752 KB
testcase_16 AC 22 ms
11,136 KB
testcase_17 AC 13 ms
10,112 KB
testcase_18 AC 15 ms
10,112 KB
testcase_19 AC 22 ms
12,800 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 26 ms
13,824 KB
testcase_23 AC 19 ms
12,160 KB
testcase_24 AC 37 ms
14,336 KB
testcase_25 AC 30 ms
13,696 KB
testcase_26 AC 8 ms
8,704 KB
testcase_27 AC 27 ms
14,208 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

import           Control.Applicative
import           Control.Monad       (replicateM)
import           Data.List           (break, concatMap)
import qualified Data.Vector.Unboxed as V
import           Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main = do
  n <- readLn
  k <- readLn
  xs <- replicateM k $ do
    [x, y] <- readInts
    return (x, y)
  let go (x, y) i
        | x == i = y
        | y == i = x
        | otherwise = i
      bs = V.fromList $ 0 : map (\i -> foldr go i xs) [1..n]
  as <- V.fromList . (0:) <$> readInts
  let cs = map (\i -> as V.! (bs V.! i)) [1..n]
      go' (i, c) (xs, ys) = let (a, _:b) = break (== c) ys
                                j = length a + 1
                            in ([(k, k + 1) | k <- [i-1,i-2..j]] ++ xs, a ++ b)
      (left, _) = foldr go' ([], [1..n]) $ zip [1..n] cs
  printf "%d\n" $ length left
  mapM_ (\(x, y) -> printf "%d %d\n" x y) left
0