結果
| 問題 | No.482 あなたの名は |
| コンテスト | |
| ユーザー |
alpha_virginis
|
| 提出日時 | 2017-02-18 00:34:28 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,082 bytes |
| 記録 | |
| コンパイル時間 | 1,170 ms |
| コンパイル使用メモリ | 146,048 KB |
| 最終ジャッジ日時 | 2024-12-30 03:09:52 |
| 合計ジャッジ時間 | 1,902 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:12:1: error: [GHC-87110]
Could not load module ‘Data.IntMap.Strict’.
It is a member of the hidden package ‘containers-0.6.8’.
Use -v to see a list of the files searched for.
|
12 | import qualified Data.IntMap.Strict as IntMap
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Main.hs:13:1: error: [GHC-87110]
Could not load module ‘Data.Map’.
It is a member of the hidden package ‘containers-0.6.8’.
Use -v to see a list of the files searched for.
|
13 | import qualified Data.Map as Map
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Maybe
import qualified Data.ByteString.Char8 as C
import Control.Monad(forM_)
import Data.Int
import Data.List
import Data.Array
import Data.Word
import Data.Bits
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Map as Map
yes :: C.ByteString
yes = "YES"
no :: C.ByteString
no = "NO"
getInts :: IO [Int]
getInts = do
ss <- C.getLine
return $ map (fst . fromJust . C.readInt) $ C.words ss
getIntss :: Int -> IO [[Int]]
getIntss 0 = return []
getIntss n = do
xs <- getInts
xss <- getIntss (n - 1)
return $ xs : xss
-- end standard template --
-- begin boolean flags template --
type Flags = IntMap.IntMap Word64
initFlags :: Flags
initFlags = IntMap.fromList (zip [0..10000] (repeat 0))
setFlag :: Int -> Flags -> Flags
setFlag i flags = IntMap.update f (i `shiftR` 6) flags
where f = \x -> Just $ x .|. (1 `shiftL` (i .&. 0x3f))
getFlag :: Int -> Flags -> Bool
getFlag i flags = ((flags IntMap.! (i `shiftR` 6)) .&. (1 `shiftL` (i .&. 0x3f))) /= 0
-- end boolean flags template --
main :: IO ()
main = do
[n,k] <- getInts
xs <- getInts
let ss = solve n k xs
C.putStrLn ss
solve :: Int -> Int -> [Int] -> C.ByteString
solve n k xs = if diff <= k && mod diff 2 == mod k 2 then yes else no
where
xs' = listArray (1,n) xs
visited = initFlags
(_, count) = f n xs' visited 0
diff = count
f :: Int -> Array Int Int -> Flags -> Int -> (Flags, Int)
f 0 xs visited count = (visited, count)
f i xs visited count = if getFlag (toEnum i) visited == True
then f (i - 1) xs visited count
else f (i - 1) xs visited' (count + count')
where
(visited', count') = g i i xs visited 0
g :: Int -> Int -> Array Int Int -> Flags -> Int -> (Flags, Int)
g s i xs visited count = if (xs ! i) == s
then (visited', count)
else g s (xs ! i) xs visited' (count + 1)
where visited' = setFlag i visited
alpha_virginis