Submission #1759031


Source Code Expand

import Control.Monad

type Board = [[Int]]

rectBoards :: Board -> (Int, Int) -> [(Int, Int)]
rectBoards board (m, n) = do
    let d = length board
    a <- [0 .. (d - 1)]
    b <- [0 .. (d - 1)]
    guard (a + m <= d)
    guard (b + n <= d)
    return (a, b)

rectangles :: Int -> [(Int, Int)]
rectangles s = do
    a <- [1 .. s]
    b <- [1 .. s `div `a]
    guard (a * b <= s)
    return (a, b)

score :: Board -> Int -> Int -> Int -> Int -> Int
score board x y m n = sum
    [(board !! j) !! i | i <- [x .. (x + m - 1)], j <- [y .. (y + n - 1)]]

scores :: Board -> [(Int, Int)] -> [(Int, Int)] -> [Int]
scores board rbs rs = do
    let d = length board
    (x,y) <- rbs
    (m,n) <- rs
    guard (x + m <= d)
    guard (y + n <= d)
    return $ score board x y m n

maxScore :: Board -> Int -> Int
maxScore board rsize =
    let rects = rectangles rsize
    in maximum $ maximum $ map (\r -> scores board (rectBoards board r) rects) rects

main :: IO ()
main = do
    n <- readLn
    board <- mapM (\_ -> map (read :: String -> Int) . words <$> getLine) [1..n]
    q <- readLn
    mapM_ (\_ -> do
        p <- readLn :: IO Int
        print $ maxScore board p
        ) [1..q]

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User atctk
Language Haskell (GHC 7.10.3)
Score 0
Code Size 1229 Byte
Status WA
Exec Time 5256 ms
Memory 10492 KB

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 0 / 50 0 / 50
Status
AC × 12
WA × 6
AC × 7
WA × 4
TLE × 9
Set Name Test Cases
Subtask1 sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Subtask2 rand0.txt, rand1.txt, rand2.txt, rand3.txt, rand4.txt, rand_max0.txt, rand_max1.txt, rand_max2.txt, rand_max3.txt, rand_max4.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Case Name Status Exec Time Memory
rand0.txt TLE 5256 ms 9596 KB
rand1.txt TLE 5256 ms 8572 KB
rand2.txt TLE 5256 ms 8444 KB
rand3.txt TLE 5255 ms 6396 KB
rand4.txt WA 956 ms 2300 KB
rand_max0.txt TLE 5256 ms 8700 KB
rand_max1.txt TLE 5256 ms 5372 KB
rand_max2.txt TLE 5256 ms 9596 KB
rand_max3.txt TLE 5256 ms 6568 KB
rand_max4.txt TLE 5256 ms 10492 KB
s1.txt AC 2 ms 636 KB
s2.txt AC 2 ms 508 KB
sub0.txt AC 8 ms 1020 KB
sub1.txt AC 9 ms 1020 KB
sub2.txt AC 11 ms 1148 KB
sub_rand_max0.txt WA 6 ms 1020 KB
sub_rand_max1.txt AC 12 ms 1148 KB
sub_rand_max2.txt WA 7 ms 1020 KB
sub_rand_max3.txt WA 7 ms 1020 KB
sub_rand_min0.txt AC 1 ms 508 KB