結果

問題 No.26 シャッフルゲーム
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 20:54:20
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 599 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 164,264 KB
実行使用メモリ 8,784 KB
最終ジャッジ日時 2023-08-30 07:22:20
合計ジャッジ時間 3,196 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,916 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 3 ms
7,824 KB
testcase_05 WA -
testcase_06 AC 3 ms
8,108 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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))
0