Submission #51388776


Source Code Expand

Copy
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import qualified Data.Vector.Unboxed as UV
import Debug.Trace
main :: IO ()
main = do
[n,k] <- bsGetLnInts
cvs <- replicateM n bsGetLnInts
let ans = abc345e n k cvs
print ans
bsGetLnInts :: IO [Int]
bsGetLnInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
--data TOP2 = E0 | E1 (Int,Int) | E2 (Int,Int) (Int,Int)
-- deriving Show
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

import qualified Data.Vector.Unboxed as UV

import Debug.Trace

main :: IO ()
main = do
  [n,k] <- bsGetLnInts
  cvs <- replicateM n bsGetLnInts
  let ans = abc345e n k cvs
  print ans

bsGetLnInts :: IO [Int]
bsGetLnInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

--data TOP2 = E0 | E1 (Int,Int) | E2 (Int,Int) (Int,Int)
--  deriving Show
-- E0 : (-1,0,-1,0), E1 : (w,d,-1,0), E2 : (w,d,x,e)

abc345e :: Int -> Int -> [[Int]] -> Int
abc345e n k cvs = ans
  where
    score0 = UV.fromList $ (0,0,-1,0) : replicate k (-1,0,-1,0)
    (ans,_,_,_) = foldl' step score0 cvs UV.! k
    step score (c:v:_) = UV.generate (succ k) g
      where
        g 0 = f (score UV.! 0) (-1,0,-1,0)
        g i = f (score UV.! i) (score UV.! pred i)

        f (-1,_,_,_) = id
        f (w,d,-1,_) | c /= d    = ins (w + v, c)
                     | otherwise = id
        f (w,d,x,e) | c /= d    = ins (w + v, c)
                    | otherwise = ins (x + v, c)

ins :: (Int,Int) -> (Int,Int,Int,Int) -> (Int,Int,Int,Int)
{-
ins (v,c) (-1,_,_,_) = (v,c,-1,0)
ins (v,c) (w,d,-1,_) | c == d = (max v w, c, -1, 0)
                     | v >= w = (v, c, w, d)
                     | otherwise = (w, d, v, c)
ins (v,c) (w,d,x,e)
  | c == d = (max v w, c, x, e)
  | v >= w = (v, c, w, d)
  | v >= x = (w, d, v, c)
  | True   = (w, d, x, e)
-}
ins (v,c) wdxe@(w,d,x,e)
  | c == d = (max v w, c, x, e)
  | v >= w = (v, c, w, d)
  | v >= x = (w, d, v, c)
  | True   = wdxe

-- Vectorで書き直し。

Submission Info

Submission Time
Task E - Colorful Subsequence
User joetheshootingst
Language Haskell (GHC 9.4.5)
Score 525
Code Size 1652 Byte
Status AC
Exec Time 1022 ms
Memory 67572 KB

Compile Error

app/Main.hs:8:1: warning: [-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()
  |
8 | import Debug.Trace
  | ^^^^^^^^^^^^^^^^^^

app/Main.hs:25:9: warning: [-Wunused-matches]
    Defined but not used: ‘n’
   |
25 | abc345e n k cvs = ans
   |         ^

app/Main.hs:29:5: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘step’:
        Patterns of type ‘UV.Vector (Int, Int, Int, Int)’,
                         ‘[Int]’ not matched:
            _ []
            _ [_]
   |
29 |     step score (c:v:_) = UV.generate (succ k) g
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

app/Main.hs:37:18: warning: [-Wunused-matches]
    Defined but not used: ‘e’
   |
37 |         f (w,d,x,e) | c /= d    = ins (w + v, c)
   |                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 38
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 6600 KB
example_01.txt AC 1 ms 6760 KB
example_02.txt AC 1 ms 6812 KB
hand_00.txt AC 1022 ms 65932 KB
hand_01.txt AC 1022 ms 65688 KB
hand_02.txt AC 92 ms 59052 KB
hand_03.txt AC 672 ms 65892 KB
hand_04.txt AC 1 ms 6768 KB
hand_05.txt AC 1 ms 6864 KB
hand_06.txt AC 5 ms 12136 KB
hand_07.txt AC 1 ms 6824 KB
random_00.txt AC 122 ms 61908 KB
random_01.txt AC 862 ms 66096 KB
random_02.txt AC 562 ms 61764 KB
random_03.txt AC 832 ms 65976 KB
random_04.txt AC 132 ms 60812 KB
random_05.txt AC 852 ms 65944 KB
random_06.txt AC 512 ms 61772 KB
random_07.txt AC 842 ms 65928 KB
random_08.txt AC 642 ms 61868 KB
random_09.txt AC 852 ms 65980 KB
random_10.txt AC 722 ms 66976 KB
random_11.txt AC 1022 ms 67572 KB
random_12.txt AC 582 ms 61636 KB
random_13.txt AC 852 ms 65932 KB
random_14.txt AC 422 ms 61620 KB
random_15.txt AC 832 ms 65864 KB
random_16.txt AC 362 ms 61720 KB
random_17.txt AC 1012 ms 65864 KB
random_18.txt AC 852 ms 65944 KB
random_19.txt AC 832 ms 65932 KB
random_20.txt AC 622 ms 61828 KB
random_21.txt AC 852 ms 65872 KB
random_22.txt AC 312 ms 62036 KB
random_23.txt AC 842 ms 65728 KB
random_24.txt AC 492 ms 61804 KB
random_25.txt AC 853 ms 65860 KB
random_26.txt AC 502 ms 61904 KB


2025-04-17 (Thu)
12:06:12 +00:00