結果

問題 No.663 セルオートマトンの逆操作
ユーザー pekempeypekempey
提出日時 2018-03-10 16:33:30
言語 Haskell
(9.8.2)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 4,337 ms
コンパイル使用メモリ 163,480 KB
実行使用メモリ 14,116 KB
最終ジャッジ日時 2023-08-04 16:33:50
合計ジャッジ時間 2,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,980 KB
testcase_01 AC 2 ms
6,972 KB
testcase_02 AC 2 ms
7,016 KB
testcase_03 AC 2 ms
7,032 KB
testcase_04 AC 2 ms
6,972 KB
testcase_05 AC 2 ms
6,968 KB
testcase_06 AC 2 ms
7,044 KB
testcase_07 AC 2 ms
7,096 KB
testcase_08 AC 2 ms
6,976 KB
testcase_09 AC 2 ms
7,116 KB
testcase_10 AC 2 ms
6,972 KB
testcase_11 AC 2 ms
7,044 KB
testcase_12 AC 3 ms
7,088 KB
testcase_13 AC 2 ms
7,232 KB
testcase_14 AC 2 ms
7,040 KB
testcase_15 AC 2 ms
7,056 KB
testcase_16 AC 3 ms
7,644 KB
testcase_17 AC 2 ms
7,164 KB
testcase_18 AC 2 ms
7,064 KB
testcase_19 AC 2 ms
6,992 KB
testcase_20 AC 2 ms
7,816 KB
testcase_21 AC 6 ms
10,732 KB
testcase_22 AC 7 ms
11,352 KB
testcase_23 AC 12 ms
12,184 KB
testcase_24 AC 22 ms
12,784 KB
testcase_25 AC 22 ms
12,992 KB
testcase_26 AC 22 ms
14,116 KB
testcase_27 AC 2 ms
7,156 KB
testcase_28 AC 3 ms
7,264 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

ソースコード

diff #

import Data.List
import Control.Monad

main = do 
  n <- readLn :: IO Int
  a <- replicateM n readLn :: IO [Int]
  print $ solve a

md :: Int
md = 10^9 + 7

type Stat = (Int, Int, Int, Int)

solve :: [Int] -> Int
solve a = let b = foldl' g [((i, j, i, j), 1) | i <- [0,1], j <- [0,1]] a
          in modsum . map snd . filter (\((h1, h2, x, y), _) -> h1 == x && h2 == y) $ b
  where
    g :: [(Stat, Int)] -> Int -> [(Stat, Int)]
    g acc a = compress (acc >>= f a)

    f :: Int -> (Stat, Int) -> [(Stat, Int)]
    f a ((h1, h2, x, y), cnt) = [((h1, h2, y, z), cnt) | z <- [0, 1], rule x y z == a]

compress :: [(Stat, Int)] -> [(Stat, Int)]
compress a = map f . groupBy (\x y -> fst x == fst y) $ a
  where
    f :: [(Stat, Int)] -> (Stat, Int)
    f x = let key = fst (head x); val = modsum . map snd $ x
          in (key, val)

modsum :: [Int] -> Int
modsum = foldl' (\x y -> (x + y) `mod` md) 0

rule :: Int -> Int -> Int -> Int
rule 0 0 0 = 0
rule 0 0 1 = 1
rule 0 1 0 = 1
rule 0 1 1 = 1
rule 1 0 0 = 0
rule 1 0 1 = 1
rule 1 1 0 = 1
rule 1 1 1 = 0
0