結果
問題 | No.26 シャッフルゲーム |
ユーザー | tottoripaper |
提出日時 | 2014-11-16 20:57:48 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 601 bytes |
コンパイル時間 | 9,612 ms |
コンパイル使用メモリ | 162,116 KB |
実行使用メモリ | 8,604 KB |
最終ジャッジ日時 | 2023-08-30 07:22:38 |
合計ジャッジ時間 | 1,621 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,844 KB |
testcase_01 | AC | 3 ms
6,840 KB |
testcase_02 | AC | 4 ms
8,504 KB |
testcase_03 | AC | 3 ms
7,508 KB |
testcase_04 | AC | 4 ms
7,736 KB |
testcase_05 | AC | 4 ms
7,892 KB |
testcase_06 | AC | 4 ms
8,112 KB |
testcase_07 | AC | 3 ms
7,716 KB |
testcase_08 | AC | 4 ms
8,352 KB |
testcase_09 | AC | 4 ms
8,604 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
ソースコード
import Control.Applicative import Control.Monad import Data.Bits readInts :: IO [Int] readInts = map read . words <$> getLine rightmost :: Int -> Int rightmost n = length $ takeWhile (not . testBit n) [0..31] swap :: Int -> Int -> Int -> Int swap x n m = x `xor` a `xor` shift a d where d = m-n a = (shift x (-d) `xor` x) .&. shift 1 n main = do n <- readLn m <- readLn query <- replicateM m readInts let query' = map (map (subtract 1)) query f [] s = 1 + rightmost s f ([p,q]:rs) s = f rs (swap s p q) in print $ f query' (shift 1 (n-1))