結果

問題 No.482 あなたの名は
ユーザー atuk721atuk721
提出日時 2017-02-17 05:49:49
言語 Haskell
(9.8.2)
結果
AC  
実行時間 853 ms / 2,000 ms
コード長 765 bytes
コンパイル時間 5,274 ms
コンパイル使用メモリ 162,884 KB
実行使用メモリ 153,796 KB
最終ジャッジ日時 2023-08-29 06:06:49
合計ジャッジ時間 16,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,196 KB
testcase_01 AC 2 ms
7,312 KB
testcase_02 AC 2 ms
7,116 KB
testcase_03 AC 2 ms
7,156 KB
testcase_04 AC 2 ms
7,084 KB
testcase_05 AC 3 ms
7,084 KB
testcase_06 AC 3 ms
7,156 KB
testcase_07 AC 6 ms
11,288 KB
testcase_08 AC 5 ms
9,920 KB
testcase_09 AC 3 ms
7,704 KB
testcase_10 AC 5 ms
9,808 KB
testcase_11 AC 6 ms
10,644 KB
testcase_12 AC 6 ms
11,272 KB
testcase_13 AC 5 ms
9,820 KB
testcase_14 AC 5 ms
9,420 KB
testcase_15 AC 822 ms
148,760 KB
testcase_16 AC 833 ms
148,796 KB
testcase_17 AC 812 ms
148,804 KB
testcase_18 AC 813 ms
148,732 KB
testcase_19 AC 793 ms
148,740 KB
testcase_20 AC 812 ms
148,780 KB
testcase_21 AC 813 ms
148,660 KB
testcase_22 AC 853 ms
149,656 KB
testcase_23 AC 802 ms
148,712 KB
testcase_24 AC 792 ms
148,664 KB
testcase_25 AC 793 ms
148,696 KB
testcase_26 AC 812 ms
148,784 KB
testcase_27 AC 833 ms
149,788 KB
testcase_28 AC 812 ms
149,644 KB
testcase_29 AC 752 ms
153,796 KB
testcase_30 AC 3 ms
7,180 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 (c + 1) xs
0