結果
| 問題 |
No.482 あなたの名は
|
| コンテスト | |
| ユーザー |
くれちー
|
| 提出日時 | 2017-02-25 02:47:02 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,066 bytes |
| コンパイル時間 | 9,484 ms |
| コンパイル使用メモリ | 184,704 KB |
| 実行使用メモリ | 192,896 KB |
| 最終ジャッジ日時 | 2025-01-03 08:37:11 |
| 合計ジャッジ時間 | 57,479 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 15 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.10.1/environments/default
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:9:38: warning: [GHC-63394] [-Wx-partial]
In the use of ‘tail’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Replace it with 'drop' 1, or use pattern matching or 'GHC.Internal.Data.List.uncons' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
9 | t2 = splitAt (pred $ j - i) (tail . snd $ t1)
| ^^^^
Main.hs:10:14: warning: [GHC-63394] [-Wx-partial]
In the use of ‘tail’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Replace it with 'drop' 1, or use pattern matching or 'GHC.Internal.Data.List.uncons' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
10 | t3 = tail . snd $ t2
| ^^^^
[2 of 2] Linking a.out
ソースコード
import Data.List (findIndex)
swap :: [a] -> Int -> Int -> [a]
swap xs a b = fst t1 ++ [xs !! pred j] ++ fst t2 ++ [xs !! pred i] ++ t3
where
i = min a b
j = max a b
t1 = splitAt (pred i) xs
t2 = splitAt (pred $ j - i) (tail . snd $ t1)
t3 = tail . snd $ t2
rep :: Integral a => [Int] -> [Int] -> Int -> a -> a
rep ds idxs i cnt
| i > length ds = cnt
| ds !! (pred i) == i = rep ds idxs (succ i) cnt
| otherwise = rep (swap ds i (idxs !! (pred i))) (swap idxs (ds !! pred i) (ds !! pred (idxs !! pred i))) (succ i) (succ cnt)
solve :: Integral a => Int -> a -> [Int] -> Bool
solve n k ds
| cnt <= k && even (k - cnt) = True
| otherwise = False
where
Just idxs = fmap (map succ) . sequenceA $ (\x -> findIndex (== x)) <$> [1..n] <*> pure ds
cnt = rep ds idxs 1 0
main = do
[n, k] <- map read . words <$> getLine
ds <- map read . words <$> getLine
putStrLn $ case solve n k ds of
True -> "YES"
False -> "NO"
くれちー