結果

問題 No.482 あなたの名は
ユーザー aimyaimy
提出日時 2017-07-14 13:59:21
言語 Haskell
(9.6.2)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 1,032 ms
コンパイル使用メモリ 164,260 KB
実行使用メモリ 44,224 KB
最終ジャッジ日時 2023-07-29 13:26:21
合計ジャッジ時間 5,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,744 KB
testcase_01 AC 2 ms
7,648 KB
testcase_02 AC 2 ms
7,568 KB
testcase_03 AC 2 ms
7,616 KB
testcase_04 AC 2 ms
7,720 KB
testcase_05 AC 2 ms
7,652 KB
testcase_06 AC 2 ms
7,616 KB
testcase_07 AC 2 ms
8,248 KB
testcase_08 AC 2 ms
8,020 KB
testcase_09 AC 2 ms
7,732 KB
testcase_10 AC 3 ms
8,128 KB
testcase_11 AC 2 ms
8,200 KB
testcase_12 AC 3 ms
8,264 KB
testcase_13 AC 2 ms
8,048 KB
testcase_14 AC 3 ms
8,000 KB
testcase_15 AC 142 ms
44,176 KB
testcase_16 AC 142 ms
44,196 KB
testcase_17 AC 142 ms
43,988 KB
testcase_18 AC 142 ms
44,124 KB
testcase_19 AC 143 ms
44,104 KB
testcase_20 AC 142 ms
44,076 KB
testcase_21 AC 143 ms
44,124 KB
testcase_22 AC 153 ms
44,168 KB
testcase_23 AC 153 ms
44,172 KB
testcase_24 AC 142 ms
44,220 KB
testcase_25 AC 151 ms
44,224 KB
testcase_26 AC 162 ms
44,176 KB
testcase_27 AC 152 ms
44,132 KB
testcase_28 AC 153 ms
44,120 KB
testcase_29 AC 92 ms
43,376 KB
testcase_30 AC 2 ms
7,692 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 Data.IntMap.Strict ((!))
import qualified Data.IntMap.Strict as M
import Data.Maybe
import Data.Bool
import Data.List

main = do
 [_,k] <- map read . words <$> getLine
 ds <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
 putStrLn $ bool "NO" "YES" (anata k ds)

anata :: Integer -> [Int] -> Bool
anata k ds = nmin <= k && even (k - nmin)
 where
  im = M.fromDistinctAscList (zip [1..] ds)
  nmin = countCycle 0 im

countCycle n im
 | M.null im = n
 | otherwise = countCycle (n+n') im''
 where
  ((k,v),im') = M.deleteFindMin im
  (n',im'') = deleteCycle k v (0, im')

deleteCycle k v (n,im)
 | k == v = (n,im)
 | otherwise = deleteCycle k (im!v) (n+1, M.delete v im)
0