結果

問題 No.482 あなたの名は
ユーザー atuk721atuk721
提出日時 2017-02-18 06:24:37
言語 Haskell
(9.8.2)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 192,076 KB
実行使用メモリ 15,696 KB
最終ジャッジ日時 2023-08-28 18:39:46
合計ジャッジ時間 7,613 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,268 KB
testcase_01 AC 2 ms
7,284 KB
testcase_02 AC 2 ms
7,312 KB
testcase_03 AC 3 ms
7,296 KB
testcase_04 AC 2 ms
7,332 KB
testcase_05 AC 2 ms
7,340 KB
testcase_06 AC 2 ms
7,336 KB
testcase_07 AC 6 ms
11,080 KB
testcase_08 AC 4 ms
9,780 KB
testcase_09 AC 3 ms
7,836 KB
testcase_10 AC 5 ms
9,636 KB
testcase_11 AC 4 ms
10,484 KB
testcase_12 AC 5 ms
10,952 KB
testcase_13 AC 4 ms
9,636 KB
testcase_14 AC 4 ms
9,268 KB
testcase_15 AC 252 ms
15,644 KB
testcase_16 AC 252 ms
15,520 KB
testcase_17 AC 252 ms
15,640 KB
testcase_18 AC 242 ms
15,684 KB
testcase_19 AC 242 ms
15,568 KB
testcase_20 AC 242 ms
15,568 KB
testcase_21 AC 242 ms
15,568 KB
testcase_22 AC 242 ms
15,696 KB
testcase_23 AC 242 ms
15,500 KB
testcase_24 AC 242 ms
15,656 KB
testcase_25 AC 242 ms
15,520 KB
testcase_26 AC 243 ms
15,616 KB
testcase_27 AC 242 ms
15,524 KB
testcase_28 AC 243 ms
15,620 KB
testcase_29 AC 242 ms
15,556 KB
testcase_30 AC 3 ms
7,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.ByteString.Char8 as B
import qualified Data.Vector.Unboxed.Mutable as V
import Data.Int (Int64)

main :: IO ()
main = do
  (n, k) <- fmap toTuple $ B.getLine
  ds <- fmap B.words $ B.getLine
  vec <- V.unsafeNew n :: IO (V.IOVector Int)
  mapM_ ((\(i, v) -> V.unsafeWrite vec i v) . (\(i, v) -> (i, flip (-) 1 . read . B.unpack $ v))) $ zip [0..] ds
  result <- sortCount n k 0 vec
  putStrLn result

toTuple :: B.ByteString -> (Int, Int64)
toTuple = (\[x, y] -> (read . B.unpack $ x, read . B.unpack $ y)) . B.words

sortCount :: Int -> Int64 -> Int -> V.IOVector Int -> IO (String)
sortCount n k i _
  | k < 0  = return "NO"
  | n == i = return $ if odd k then "NO" else "YES"
sortCount n k i xs = do
  a1 <- V.unsafeRead xs i
  if a1 == i
     then sortCount n k (i + 1) xs
     else V.unsafeSwap xs i a1 >> sortCount n (k - 1) i xs
0