結果

問題 No.326 あみだますたー
ユーザー tottoripaper
提出日時 2018-03-09 15:29:38
言語 Haskell
(9.10.1)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 14,388 ms
コンパイル使用メモリ 200,960 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-10-08 15:07:42
合計ジャッジ時間 11,554 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0