結果

問題 No.223 1マス指定の魔方陣
ユーザー こまるこまる
提出日時 2020-11-04 22:59:09
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,229 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 168,832 KB
最終ジャッジ日時 2024-04-27 03:31:26
合計ジャッジ時間 931 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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:18:27: error: [GHC-87543]
    Ambiguous occurrence ‘.^.’.
    It could refer to
       either ‘Data.Bits..^.’,
              imported from ‘Data.Bits’ at Main.hs:3:1-26,
           or ‘Main..^.’, defined at Main.hs:30:1.
   |
18 |       item = if (((j + 1) .^. (i + 1)) .&. 2) /= 0 then n * n - 1 - k else k
   |                           ^^^

Main.hs:25:39: error: [GHC-87543]
    Ambiguous occurrence ‘.^.’.
    It could refer to
       either ‘Data.Bits..^.’,
              imported from ‘Data.Bits’ at Main.hs:3:1-26,
           or ‘Main..^.’, defined at Main.hs:30:1.
   |
25 |     putStr . (++ sep) . show $ (item1 .^. item2 .^. z) + 1
   |                                       ^^^

Main.hs:25:49: error: [GHC-87543]
    Ambiguous occurrence ‘.^.’.
    It could refer to
       either ‘Data.Bits..^.’,
              imported from ‘Data.Bits’ at Main.hs:3:1-26,
           or ‘Main..^.’, defined at Main.hs:30:1.
   |
25 |     putStr . (++ sep) . show $ (item1 .^. item2 .^. z) + 1
   |                                                 ^^^

ソースコード

diff #

{-# LANGUAGE BangPatterns #-}

import           Data.Bits
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Unboxed.Mutable       as VUM

main :: IO ()
main = do
  [n, x', y', z'] <- map (read :: String -> Int) . words <$> getLine
  let
    x = x' - 1
    y = y' - 1
    z = z' - 1
  as <- VUM.unsafeNew 256 :: IO (VUM.IOVector Int)
  rep n $ \i -> rep n $ \j -> do
    let
      k = i * n + j
      item = if (((j + 1) .^. (i + 1)) .&. 2) /= 0 then n * n - 1 - k else k
    VUM.unsafeWrite as (i * 16 + j) item
  rep n $ \i -> rep n $ \j -> do
    let
      sep = if j `mod` n == (n - 1)  then "\n" else " "
    item1 <- VUM.unsafeRead as (i * 16 + j) 
    item2 <- VUM.unsafeRead as (y * 16 + x)
    putStr . (++ sep) . show $ (item1 .^. item2 .^. z) + 1

infixl 6 .^.

(.^.) :: Bits b => b -> b -> b
(.^.) = xor
{-# INLINE (.^.) #-}

stream :: Monad m => Int -> Int -> VFSM.Stream m Int
stream !l !r = VFSM.Stream step l
  where
    step x
      | x < r     = return $ VFSM.Yield x (x + 1)
      | otherwise = return $ VFSM.Done
    {-# INLINE [0] step #-}
{-# INLINE [1] stream #-}

rep :: Monad m => Int -> (Int -> m ()) -> m ()
rep n = flip VFSM.mapM_ (stream 0 n)
{-# INLINE rep #-}

0