結果

問題 No.482 あなたの名は
ユーザー atuk721atuk721
提出日時 2017-02-17 05:35:27
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 771 bytes
コンパイル時間 2,688 ms
コンパイル使用メモリ 165,168 KB
実行使用メモリ 161,164 KB
最終ジャッジ日時 2023-08-29 06:05:34
合計ジャッジ時間 17,351 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,228 KB
testcase_01 AC 3 ms
7,112 KB
testcase_02 AC 3 ms
7,164 KB
testcase_03 AC 2 ms
7,308 KB
testcase_04 AC 3 ms
7,104 KB
testcase_05 AC 3 ms
7,200 KB
testcase_06 AC 2 ms
7,112 KB
testcase_07 AC 6 ms
10,828 KB
testcase_08 WA -
testcase_09 AC 3 ms
7,604 KB
testcase_10 AC 4 ms
9,400 KB
testcase_11 AC 6 ms
10,116 KB
testcase_12 WA -
testcase_13 AC 5 ms
9,388 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 762 ms
156,948 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 762 ms
156,844 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 782 ms
156,892 KB
testcase_24 AC 752 ms
156,940 KB
testcase_25 AC 771 ms
156,908 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 773 ms
156,904 KB
testcase_29 AC 652 ms
154,872 KB
testcase_30 AC 2 ms
7,140 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.Array.IO as I

main :: IO ()
main = do
  [n, k] <- fmap (map read . words) $ getLine :: IO [Integer]
  ds <- fmap (map read . words) $ getLine :: IO [Integer]
  is <- I.newListArray (1, n) ds :: IO (I.IOArray Integer Integer)
  result <- sortCount n 1 0 is

  putStrLn $ if result > k || (odd result && even k) || (even result && odd k)
             then "NO"
             else "YES"

sortCount :: Integer -> Integer -> Integer -> I.IOArray Integer Integer -> IO (Integer)
sortCount n i c _
  | n + 1 == i = return c
sortCount n i c xs = do
  a1 <- I.readArray xs i
  if a1 == i
     then sortCount n (i + 1) c xs
     else do
      a2 <- I.readArray xs a1
      I.writeArray xs i a2
      I.writeArray xs a1 a1
      sortCount n (i + 1) (c + 1) xs
0