Submission #43767773
Source Code Expand
Copy
importData.ArrayimportData.BitsimportData.Listmain = don <- readLnas <- map read . words <$> getLinelet ans = abc310f n asprint anstype State = Array Int Int -- 作れる数のビット集合 → 場合の数abc310f::Int->Int->Intabc310f n as = divm answer denomwhereinitial = accumArray (+) 0 (0,ub) [(0,1)]final = foldl' {-'-} step initial asanswer = foldl' {-'-} addm 0 [final ! i | i <- [512..ub]]denom = foldl' {-'-} mulm 1 asub = 1023
import Data.Array import Data.Bits import Data.List main = do n <- readLn as <- map read . words <$> getLine let ans = abc310f n as print ans type State = Array Int Int -- 作れる数のビット集合 → 場合の数 abc310f :: Int -> [Int] -> Int abc310f n as = divm answer denom where initial = accumArray (+) 0 (0,ub) [(0,1)] final = foldl' {-'-} step initial as answer = foldl' {-'-} addm 0 [final ! i | i <- [512..ub]] denom = foldl' {-'-} mulm 1 as ub = 1023 step :: State -> Int -> State step m ai = accumArray addm 0 (0,ub) $ [ (s, mulm cnt (ai - 10)) | ai > 10, (s, cnt) <- assocs m] ++ [ (bs2ix bs1, cnt) | (s, cnt) <- assocs m, let bs = ix2bs s , x <- [1 .. min 10 ai] , let bs1 = bs .|. (shiftL bs x .&. mask) ] mask = 2047 -- 添え字からビット集合 ix2bs i = shiftL i 1 .|. 1 -- ビット集合から添え字 bs2ix b = shiftR b 1 -- モジュロ演算 modBase = 998244353 reg x = mod x modBase addm x y = reg (x + y) mulm x y = reg (x * y) divm x y = powerish mulm x y (modBase - 2) powerish mul i a b = foldl' {-'-} mul i [p | (b,p) <- zip bs ps, odd b] where bs = takeWhile (0 /=) $ iterate (flip shiftR 1) b ps = iterate (\x -> mul x x) a
Submission Info
Submission Time | |
---|---|
Task | F - Make 10 Again |
User | joetheshootingst |
Language | Haskell (GHC 8.8.3) |
Score | 500 |
Code Size | 1269 Byte |
Status | AC |
Exec Time | 34 ms |
Memory | 5500 KB |
Compile Error
Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 12 ms | 3804 KB |
001.txt | AC | 5 ms | 4048 KB |
002.txt | AC | 3 ms | 3928 KB |
003.txt | AC | 3 ms | 3628 KB |
004.txt | AC | 3 ms | 4088 KB |
005.txt | AC | 3 ms | 4108 KB |
006.txt | AC | 11 ms | 5500 KB |
007.txt | AC | 34 ms | 4952 KB |
008.txt | AC | 4 ms | 3880 KB |
009.txt | AC | 14 ms | 4924 KB |
010.txt | AC | 29 ms | 4956 KB |
011.txt | AC | 29 ms | 4920 KB |
012.txt | AC | 15 ms | 5028 KB |
013.txt | AC | 25 ms | 5056 KB |
014.txt | AC | 27 ms | 4832 KB |
015.txt | AC | 32 ms | 4836 KB |
016.txt | AC | 34 ms | 4912 KB |
017.txt | AC | 32 ms | 4952 KB |
018.txt | AC | 33 ms | 4940 KB |
019.txt | AC | 28 ms | 5024 KB |
020.txt | AC | 29 ms | 5020 KB |
021.txt | AC | 33 ms | 4924 KB |
022.txt | AC | 17 ms | 5000 KB |
023.txt | AC | 23 ms | 5112 KB |
024.txt | AC | 20 ms | 4840 KB |
025.txt | AC | 17 ms | 4996 KB |
026.txt | AC | 17 ms | 5020 KB |
027.txt | AC | 25 ms | 4816 KB |
028.txt | AC | 18 ms | 4892 KB |
029.txt | AC | 18 ms | 4988 KB |
030.txt | AC | 27 ms | 4936 KB |
031.txt | AC | 25 ms | 4956 KB |
032.txt | AC | 22 ms | 4960 KB |
033.txt | AC | 22 ms | 4832 KB |
034.txt | AC | 21 ms | 5036 KB |
035.txt | AC | 28 ms | 4832 KB |
036.txt | AC | 21 ms | 4952 KB |
037.txt | AC | 27 ms | 4920 KB |
example0.txt | AC | 6 ms | 4096 KB |
example1.txt | AC | 7 ms | 4732 KB |