Submission #12902431
Source Code Expand
{-# LANGUAGE BangPatterns #-}
import Control.Exception (assert)
import Control.Monad
import Control.Monad.Primitive
import qualified Control.Monad.ST as ST
import qualified Data.Array.IO as IO
import qualified Data.Array.ST as ST
import qualified Data.Array.Unboxed as A
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Foldable
import Data.List
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import qualified Data.Vector as VB
import qualified Data.Vector.Mutable as VBM
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Debug.Trace
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine
inf :: Int
inf = 10^18
quickSortVec l u arr
| l >= u = return ()
| otherwise = do
VM.unsafeSwap arr l ((u+l)`div`2)
t <- VM.unsafeRead arr l
let i = l
j = u + 1
nj <- loopVec t u i j arr
VM.unsafeSwap arr l nj
quickSortVec l (nj-1) arr
quickSortVec (nj+1) u arr
loopVec !t !u !i !j arr = do
ni <- doWhile i (+1) (< t)
nj <- doWhile j (subtract 1) (> t)
if ni > nj
then return nj
else do VM.unsafeSwap arr ni nj
loopVec t u ni nj arr
where
{-# INLINE doWhile #-}
doWhile k op p
| nk > u = return nk
| otherwise = do
x <- VM.unsafeRead arr nk
if p x then
doWhile nk op p
else
return nk
where
nk = op k
main = do
[n, c] <- getIntList
ps <- VM.new n
forM_ [0..(n-1)] $ \i -> do
[s, t, c] <- getIntList
VM.write ps i (s, t, c)
quickSortVec 0 (n-1) ps
tvs <- VM.new 30
VM.set tvs ((0,0) :: (Int, Int))
let findTv :: Int -> Int -> Int -> IO Int
findTv i s c = do
(onCh, busyTo) <- VM.read tvs i
if onCh == 0 || busyTo < s || (onCh == c && busyTo == s)
then return i
else findTv (i+1) s c
solve :: Int -> Int -> IO Int
solve i res | i == n = return res
| otherwise = do
(s, t, c) <- VM.read ps i
tvNum <- findTv 0 s c
let res' = max res (tvNum + 1)
VM.write tvs tvNum (c, t)
solve (i+1) res'
ans <- solve 0 0
print ans
Submission Info
| Submission Time | |
|---|---|
| Task | D - Recording |
| User | unnohideyuki |
| Language | Haskell (GHC 7.10.3) |
| Score | 400 |
| Code Size | 3216 Byte |
| Status | AC |
| Exec Time | 106 ms |
| Memory | 11900 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 105 ms | 11900 KiB |
| 02.txt | AC | 105 ms | 11900 KiB |
| 03.txt | AC | 106 ms | 11772 KiB |
| 04.txt | AC | 106 ms | 11900 KiB |
| 05.txt | AC | 102 ms | 11900 KiB |
| 06.txt | AC | 50 ms | 6524 KiB |
| 07.txt | AC | 34 ms | 4604 KiB |
| 08.txt | AC | 2 ms | 1020 KiB |
| 09.txt | AC | 103 ms | 11772 KiB |
| 10.txt | AC | 104 ms | 11772 KiB |
| 11.txt | AC | 103 ms | 11772 KiB |
| 12.txt | AC | 2 ms | 380 KiB |
| 13.txt | AC | 2 ms | 508 KiB |
| 14.txt | AC | 2 ms | 508 KiB |
| 15.txt | AC | 2 ms | 508 KiB |
| 16.txt | AC | 105 ms | 11772 KiB |
| 17.txt | AC | 103 ms | 11772 KiB |
| 18.txt | AC | 104 ms | 11900 KiB |
| 19.txt | AC | 105 ms | 11772 KiB |
| sample_01.txt | AC | 2 ms | 380 KiB |
| sample_02.txt | AC | 2 ms | 380 KiB |
| sample_03.txt | AC | 2 ms | 508 KiB |