{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE NegativeLiterals #-}
{-# LANGUAGE HexFloatLiterals #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BlockArguments #-}
-- {-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -O3 #-}
{-# OPTIONS_GHC -Wno-tabs #-}
import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.Extra
import Control.Monad.ST
import Data.Bool
import Data.Bits
import Data.Char
import Data.Tuple.Extra hiding ( (&&&), (***) )
import Data.List hiding ( (!?) )
import Data.List.Extra hiding ( (!?) )
import Data.Maybe
import Data.Either
import Data.Function
import qualified Data.Set as Set
import qualified Data.IntSet as ISet
import qualified Data.Map as Map
import qualified Data.IntMap as IMap
import qualified Data.Sequence as Seq
import Data.Sequence ( (<|), (|>), (><), ViewL(..), ViewR(..) )
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST.Safe
import Data.Array.MArray
import Data.STRef
import Text.Printf
import Debug.Trace
import Data.Array.Unsafe
readInt = fst . fromJust . B.readInt <$> B.getLine
readInteger = fst . fromJust . B.readInteger <$> B.getLine
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine
readStr = trim . B.unpack <$> B.getLine
readStrs = map B.unpack . B.words <$> B.getLine
yesno = bool "No" "Yes"
mp [ a, b ] = ( a, b )
count a as = length $ filter ( == a ) as
countIf f as = length $ filter f as
swapArrayElem a i j = do
x <- readArray a i
y <- readArray a j
writeArray a i y
writeArray a j x
a !? i
| inRange ( bounds a ) i = Just $ a ! i
| otherwise = Nothing
printList :: Show a => [a] -> IO ()
printList = putStrLn . intercalate " " . map show
main = do
[ n, m ] <- readInts
[ ps, vs ] <- transpose <$> replicateM n readInts
let
solve ps vs = runST do
dp <- newArray ( ( 0, 0 ), ( n, m ) ) ( minBound `div` 2 ) :: ST s ( STUArray s ( Int, Int ) Int )
writeArray dp ( 0, 0 ) 0
forM_ ( zip3 [ 0 .. ] ps vs ) $ \( i, p, v ) -> do
forM_ [ 0 .. m ] $ \j -> do
modifyArray dp ( i + 1, j ) =<< max <$> readArray dp ( i, j )
when ( j + p <= m ) do
modifyArray dp ( i + 1, j + p ) =<< max . ( v + ) <$> readArray dp ( i, j )
forM_ [ 0 .. n ] $ \i -> do
forM_ [ 1 .. m ] $ \j -> do
modifyArray dp ( i, j ) =<< max <$> readArray dp ( i, j - 1 )
unsafeFreeze dp
!dp1 = solve ps vs
!dp2 = solve ( reverse ps ) ( reverse vs )
ma = maximum do
j <- [ 0 .. m ]
return $ dp1 ! ( n, j )
f True False = 'A'
f True True = 'B'
f _ _ = 'C'
putStrLn $ map ( uncurry f ) do
( i, p, v ) <- zip3 [ 0 .. ] ps vs
let
inc = or do
j <- [ 0 .. m - p ]
return $ dp1 ! ( i, j ) + dp2 ! ( n - 1 - i, m - p - j ) + v == ma
exc = or do
j <- [ 0 .. m ]
return $ dp1 ! ( i, j ) + dp2 ! ( n - 1 - i, m - j ) == ma
return ( inc, exc )
Configuration is affected by the following files:
- cabal.project
- cabal.project.freeze
- cabal.project.local
app/Main.hs:22:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Control.Applicative’ is redundant
except perhaps to import instances from ‘Control.Applicative’
To import instances alone, use: import Control.Applicative()
|
22 | import Control.Applicative
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:23:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Control.Arrow’ is redundant
except perhaps to import instances from ‘Control.Arrow’
To import instances alone, use: import Control.Arrow()
|
23 | import Control.Arrow
| ^^^^^^^^^^^^^^^^^^^^
app/Main.hs:25:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Control.Monad.Extra’ is redundant
except perhaps to import instances from ‘Control.Monad.Extra’
To import instances alone, use: import Control.Monad.Extra()
|
25 | import Control.Monad.Extra
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:29:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Bits’ is redundant
except perhaps to import instances from ‘Data.Bits’
To import instances alone, use: import Data.Bits()
|
29 | import Data.Bits
| ^^^^^^^^^^^^^^^^
app/Main.hs:30:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Char’ is redundant
except perhaps to import instances from ‘Data.Char’
To import instances alone, use: import Data.Char()
|
30 | import Data.Char
| ^^^^^^^^^^^^^^^^
app/Main.hs:32:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Tuple.Extra’ is redundant
except perhaps to import instances from ‘Data.Tuple.Extra’
To import instances alone, use: import Data.Tuple.Extra()
|
32 | import Data.Tuple.Extra hiding ( (&&&), (***) )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:36:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Either’ is redundant
except perhaps to import instances from ‘Data.Either’
To import instances alone, use: import Data.Either()
|
36 | import Data.Either
| ^^^^^^^^^^^^^^^^^^
app/Main.hs:37:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Function’ is redundant
except perhaps to import instances from ‘Data.Function’
To import instances alone, use: import Data.Function()
|
37 | import Data.Function
| ^^^^^^^^^^^^^^^^^^^^
app/Main.hs:39:1: warning: [GHC-66111] [-Wunused-imports]
The qualified import of ‘Data.Set’ is redundant
except perhaps to import instances from ‘Data.Set’
To import instances alone, use: import Data.Set()
|
39 | import qualified Data.Set as Set
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:40:1: warning: [GHC-66111] [-Wunused-imports]
The qualified import of ‘Data.IntSet’ is redundant
except perhaps to import instances from ‘Data.IntSet’
To import instances alone, use: import Data.IntSet()
|
40 | import qualified Data.IntSet as ISet
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:41:1: warning: [GHC-66111] [-Wunused-imports]
The qualified import of ‘Data.Map’ is redundant
except perhaps to import instances from ‘Data.Map’
To import instances alone, use: import Data.Map()
|
41 | import qualified Data.Map as Map
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:42:1: warning: [GHC-66111] [-Wunused-imports]
The qualified import of ‘Data.IntMap’ is redundant
except perhaps to import instances from ‘Data.IntMap’
To import instances alone, use: import Data.IntMap()
|
42 | import qualified Data.IntMap as IMap
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:43:1: warning: [GHC-66111] [-Wunused-imports]
The qualified import of ‘Data.Sequence’ is redundant
except perhaps to import instances from ‘Data.Sequence’
To import instances alone, use: import Data.Sequence()
|
43 | import qualified Data.Sequence as Seq
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:44:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Sequence’ is redundant
except perhaps to import instances from ‘Data.Sequence’
To import instances alone, use: import Data.Sequence()
|
44 | import Data.Sequence ( (<|), (|>), (><), ViewL(..), ViewR(..) )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:51:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.STRef’ is redundant
except perhaps to import instances from ‘Data.STRef’
To import instances alone, use: import Data.STRef()
|
51 | import Data.STRef
| ^^^^^^^^^^^^^^^^^
app/Main.hs:53:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Text.Printf’ is redundant
except perhaps to import instances from ‘Text.Printf’
To import instances alone, use: import Text.Printf()
|
53 | import Text.Printf
| ^^^^^^^^^^^^^^^^^^
app/Main.hs:54:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Debug.Trace’ is redundant
except perhaps to import instances from ‘Debug.Trace’
To import instances alone, use: import Debug.Trace()
|
54 | import Debug.Trace
| ^^^^^^^^^^^^^^^^^^
app/Main.hs:58:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: readInt :: IO Int
|
58 | readInt = fst . fromJust . B.readInt <$> B.getLine
| ^^^^^^^
app/Main.hs:58:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘readInt’
|
58 | readInt = fst . fromJust . B.readInt <$> B.getLine
| ^^^^^^^
app/Main.hs:59:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: readInteger :: IO Integer
|
59 | readInteger = fst . fromJust . B.readInteger <$> B.getLine
| ^^^^^^^^^^^
app/Main.hs:59:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘readInteger’
|
59 | readInteger = fst . fromJust . B.readInteger <$> B.getLine
| ^^^^^^^^^^^
app/Main.hs:60:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: readInts :: IO [Int]
|
60 | readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
| ^^^^^^^^
app/Main.hs:61:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature:
readIntegers :: IO [Integer]
|
61 | readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine
| ^^^^^^^^^^^^
app/Main.hs:61:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘readIntegers’
|
61 | readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine
| ^^^^^^^^^^^^
app/Main.hs:62:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: readStr :: IO String
|
62 | readStr = trim . B.unpack <$> B.getLine
| ^^^^^^^
app/Main.hs:62:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘readStr’
|
62 | readStr = trim . B.unpack <$> B.getLine
| ^^^^^^^
app/Main.hs:63:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: readStrs :: IO [[Char]]
|
63 | readStrs = map B.unpack . B.words <$> B.getLine
| ^^^^^^^^
app/Main.hs:63:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘readStrs’
|
63 | readStrs = map B.unpack . B.words <$> B.getLine
| ^^^^^^^^
app/Main.hs:65:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: yesno :: Bool -> String
|
65 | yesno = bool "No" "Yes"
| ^^^^^
app/Main.hs:65:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘yesno’
|
65 | yesno = bool "No" "Yes"
| ^^^^^
app/Main.hs:65:14: warning: [GHC-18042] [-Wtype-defaults]
• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraint
Data.String.IsString a0 arising from the literal ‘"No"’
• In the first argument of ‘bool’, namely ‘"No"’
In the expression: bool "No" "Yes"
In an equation for ‘yesno’: yesno = bool "No" "Yes"
|
65 | yesno = bool "No" "Yes"
| ^^^^
app/Main.hs:66:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: mp :: [b] -> (b, b)
|
66 | mp [ a, b ] = ( a, b )
| ^^
app/Main.hs:66:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘mp’
|
66 | mp [ a, b ] = ( a, b )
| ^^
app/Main.hs:66:1: warning: [GHC-62161] [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘mp’:
Patterns of type ‘[b]’ not matched:
[]
[_]
(_:_:_:_)
|
66 | mp [ a, b ] = ( a, b )
| ^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:68:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature:
count :: Eq a => a -> [a] -> Int
|
68 | count a as = length $ filter ( == a ) as
| ^^^^^
app/Main.hs:68:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘count’
|
68 | count a as = length $ filter ( == a ) as
| ^^^^^
app/Main.hs:69:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature:
countIf :: (a -> Bool) -> [a] -> Int
|
69 | countIf f as = length $ filter f as
| ^^^^^^^
app/Main.hs:69:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘countIf’
|
69 | countIf f as = length $ filter f as
| ^^^^^^^
app/Main.hs:71:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature:
swapArrayElem :: (MArray a e m, Ix i) => a i e -> i -> i -> m ()
|
71 | swapArrayElem a i j = do
| ^^^^^^^^^^^^^
app/Main.hs:71:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘swapArrayElem’
|
71 | swapArrayElem a i j = do
| ^^^^^^^^^^^^^
app/Main.hs:77:3: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature:
(!?) :: Ix i => Array i a -> i -> Maybe a
|
77 | a !? i
| ^^
app/Main.hs:77:3: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘!?’
|
77 | a !? i
| ^^
app/Main.hs:82:1: warning: [GHC-40910] [-Wunused-top-binds]
Defined but not used: ‘printList’
|
82 | printList = putStrLn . intercalate " " . map show
| ^^^^^^^^^
app/Main.hs:84:1: warning: [GHC-38417] [-Wmissing-signatures]
Top-level binding with no type signature: main :: IO ()
|
84 | main = do
| ^^^^
app/Main.hs:88:23: warning: [GHC-63397] [-Wname-shadowing]
This binding for ‘ps’ shadows the existing binding
bound at app/Main.hs:86:11
|
88 | solve ps vs = runST do
| ^^
app/Main.hs:88:26: warning: [GHC-63397] [-Wname-shadowing]
This binding for ‘vs’ shadows the existing binding
bound at app/Main.hs:86:15
|
88 | solve ps vs = runST do
| ^^
Configuration is affected by the following files:
- cabal.project
- cabal.project.freeze
- cabal.project.local