結果
問題 |
No.482 あなたの名は
|
ユーザー |
![]() |
提出日時 | 2017-02-17 05:56:55 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 583 ms / 2,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 2,670 ms |
コンパイル使用メモリ | 172,384 KB |
実行使用メモリ | 65,280 KB |
最終ジャッジ日時 | 2024-12-30 21:59:21 |
合計ジャッジ時間 | 12,777 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
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
ソースコード
import Data.Int import qualified Data.Array.IO as I main :: IO () main = do [n, k] <- fmap (map read . words) $ getLine :: IO [Int64] ds <- fmap (map read . words) $ getLine :: IO [Int64] is <- I.newListArray (1, n) ds :: IO (I.IOUArray Int64 Int64) result <- sortCount n 1 0 is putStrLn $ if result > k || (odd result && even k) || (even result && odd k) then "NO" else "YES" sortCount :: Int64 -> Int64 -> Int64 -> I.IOUArray Int64 Int64 -> IO (Int64) 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