提出 #9534064
ソースコード 拡げる
import Control.Monad
import qualified Control.Monad.ST as ST
import Data.Array.IO
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Maybe
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
rollingHash :: BS.ByteString -> Int -> (V.Vector Word, V.Vector Word)
rollingHash s b = ST.runST $ do
let sz = BS.length s
b' = fromIntegral b
h <- VM.new (sz+1)
VM.write h 0 (0::Word)
power <- VM.new (sz+1)
VM.write power 0 (1::Word)
forM_ [0..(sz-1)] $ \i -> do
powi <- VM.read power i
VM.write power (i+1) (powi * b')
hi <- VM.read h i
let si = fromIntegral $ ord $ BS.index s i
VM.write h (i+1) (hi * b' + si)
h' <- V.freeze h
power' <- V.freeze power
return (h', power')
getRH :: (V.Vector Word, V.Vector Word) -> Int -> Int -> Word
getRH (h, power) l r = hr - pr_1 * hl
where hr = h V.! r
pr_1 = power V.! (r-l)
hl = h V.! l
bisectRight :: Ord a => (Int -> a) -> a -> Int -> Int -> Int
bisectRight f x lo hi
| lo >= hi = lo
| x < f mid = bisectRight f x lo mid
| otherwise = bisectRight f x (mid+1) hi
where
mid = lo + (hi - lo) `div` 2
readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine
check' i j f | i > j = False
| otherwise = f i || check' (i+1) j f
main = do
n <- getInt
s <- BS.getLine
let rh1 = rollingHash s 100000007
rh2 = rollingHash s 10007
check k =
check' 0 (n-2*k) $ \i ->
let hi1 = getRH rh1 i (i+k)
hi2 = getRH rh2 i (i+k)
f = (\j -> (hi1 == getRH rh1 (i+k+j) (i+j+2*k) &&
hi2 == getRH rh2 (i+k+j) (i+j+2*k)))
in
check' 0 (n-i-2*k) f
ans = bisectRight (not . check) False 0 (n `div` 2 + 1) - 1
print ans
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Who Says a Pun? |
| ユーザ | unnohideyuki |
| 言語 | Haskell (GHC 7.10.3) |
| 得点 | 0 |
| コード長 | 1978 Byte |
| 結果 | TLE |
| 実行時間 | 2107 ms |
| メモリ | 1276 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 500 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-00, 00-sample-01, 00-sample-02 |
| All | 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 01-handmade-07, 01-handmade-08, 01-handmade-09, 01-handmade-10, 01-handmade-11, 01-handmade-12, 02-binary-13, 02-binary-14, 02-binary-15, 02-binary-16, 02-binary-17, 02-binary-18, 02-binary-19, 02-binary-20, 02-binary-21, 02-binary-22, 02-binary-23, 03-BigRandom-24, 03-BigRandom-25, 03-BigRandom-26, 03-BigRandom-27, 03-BigRandom-28, 03-BigRandom-29, 03-BigRandom-30, 03-BigRandom-31, 03-BigRandom-32, 03-BigRandom-33, 03-BigRandom-34, 03-BigRandom-35, 03-BigRandom-36, 03-BigRandom-37, 03-BigRandom-38, 03-BigRandom-39, 03-BigRandom-40, 03-BigRandom-41, 03-BigRandom-42, 03-BigRandom-43, 03-BigRandom-44, 03-BigRandom-45, 03-BigRandom-46, 03-BigRandom-47, 03-BigRandom-48, 03-BigRandom-49, 03-BigRandom-50, 03-BigRandom-51, 03-BigRandom-52, 03-BigRandom-53, 03-BigRandom-54, 04-zero-55, 04-zero-56, 05-AllRandom-57, 05-AllRandom-58, 05-AllRandom-59, 05-AllRandom-60, 05-AllRandom-61, 05-AllRandom-62, 05-AllRandom-63, 05-AllRandom-64, 05-AllRandom-65, 05-AllRandom-66, 05-AllRandom-67, 05-AllRandom-68, 05-AllRandom-69 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-00 | AC | 1 ms | 380 KiB |
| 00-sample-01 | AC | 1 ms | 380 KiB |
| 00-sample-02 | AC | 1 ms | 380 KiB |
| 01-handmade-03 | AC | 2 ms | 764 KiB |
| 01-handmade-04 | AC | 318 ms | 1276 KiB |
| 01-handmade-05 | AC | 2 ms | 1020 KiB |
| 01-handmade-06 | AC | 2 ms | 1020 KiB |
| 01-handmade-07 | AC | 2 ms | 1020 KiB |
| 01-handmade-08 | AC | 2 ms | 764 KiB |
| 01-handmade-09 | TLE | 2103 ms | 1276 KiB |
| 01-handmade-10 | TLE | 2103 ms | 1276 KiB |
| 01-handmade-11 | AC | 307 ms | 1276 KiB |
| 01-handmade-12 | AC | 307 ms | 1276 KiB |
| 02-binary-13 | AC | 1466 ms | 1148 KiB |
| 02-binary-14 | TLE | 2103 ms | 1276 KiB |
| 02-binary-15 | AC | 1833 ms | 1148 KiB |
| 02-binary-16 | TLE | 2103 ms | 1276 KiB |
| 02-binary-17 | TLE | 2103 ms | 1276 KiB |
| 02-binary-18 | TLE | 2103 ms | 1276 KiB |
| 02-binary-19 | AC | 1328 ms | 1148 KiB |
| 02-binary-20 | AC | 1664 ms | 1148 KiB |
| 02-binary-21 | AC | 1359 ms | 1148 KiB |
| 02-binary-22 | AC | 1222 ms | 1148 KiB |
| 02-binary-23 | AC | 977 ms | 1148 KiB |
| 03-BigRandom-24 | AC | 14 ms | 1276 KiB |
| 03-BigRandom-25 | AC | 11 ms | 1276 KiB |
| 03-BigRandom-26 | AC | 61 ms | 1276 KiB |
| 03-BigRandom-27 | AC | 162 ms | 1276 KiB |
| 03-BigRandom-28 | AC | 480 ms | 1276 KiB |
| 03-BigRandom-29 | AC | 207 ms | 1276 KiB |
| 03-BigRandom-30 | AC | 557 ms | 1276 KiB |
| 03-BigRandom-31 | AC | 105 ms | 1276 KiB |
| 03-BigRandom-32 | AC | 357 ms | 1276 KiB |
| 03-BigRandom-33 | AC | 418 ms | 1276 KiB |
| 03-BigRandom-34 | AC | 4 ms | 1276 KiB |
| 03-BigRandom-35 | AC | 381 ms | 1276 KiB |
| 03-BigRandom-36 | AC | 107 ms | 1276 KiB |
| 03-BigRandom-37 | AC | 12 ms | 1276 KiB |
| 03-BigRandom-38 | AC | 64 ms | 1276 KiB |
| 03-BigRandom-39 | AC | 5 ms | 1276 KiB |
| 03-BigRandom-40 | AC | 292 ms | 1276 KiB |
| 03-BigRandom-41 | AC | 48 ms | 1276 KiB |
| 03-BigRandom-42 | AC | 28 ms | 1276 KiB |
| 03-BigRandom-43 | AC | 17 ms | 1276 KiB |
| 03-BigRandom-44 | AC | 158 ms | 1276 KiB |
| 03-BigRandom-45 | AC | 415 ms | 1276 KiB |
| 03-BigRandom-46 | AC | 262 ms | 1276 KiB |
| 03-BigRandom-47 | AC | 211 ms | 1276 KiB |
| 03-BigRandom-48 | AC | 19 ms | 1276 KiB |
| 03-BigRandom-49 | AC | 104 ms | 1276 KiB |
| 03-BigRandom-50 | AC | 264 ms | 1276 KiB |
| 03-BigRandom-51 | AC | 16 ms | 1276 KiB |
| 03-BigRandom-52 | AC | 129 ms | 1276 KiB |
| 03-BigRandom-53 | AC | 149 ms | 1276 KiB |
| 03-BigRandom-54 | AC | 43 ms | 1276 KiB |
| 04-zero-55 | AC | 1 ms | 508 KiB |
| 04-zero-56 | AC | 1 ms | 508 KiB |
| 05-AllRandom-57 | TLE | 2107 ms | 1148 KiB |
| 05-AllRandom-58 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-59 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-60 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-61 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-62 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-63 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-64 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-65 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-66 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-67 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-68 | TLE | 2103 ms | 1148 KiB |
| 05-AllRandom-69 | TLE | 2103 ms | 1148 KiB |