Submission #48028582
Source Code Expand
Copy
importControl.MonadimportqualifiedData.ByteString.CharasBSimportData.CharimportData.ListimportqualifiedData.IntMapasIMmain::IO()main = do[n,k] <- bsGetLnIntsxys <- replicateM n bsGetLnIntslet ans = abc330f n k xysprint ansbsGetLnInts::IOIntbsGetLnInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLineabc330f::Int->Int->Int->Intabc330f n k xys = satwherexm = mkfunc $ IM.fromListWith (+) [(x, 1) | x:_ <- xys] -- X軸について数える
import Control.Monad import qualified Data.ByteString.Char8 as BS import Data.Char import Data.List import qualified Data.IntMap as IM main :: IO () main = do [n,k] <- bsGetLnInts xys <- replicateM n bsGetLnInts let ans = abc330f n k xys print ans bsGetLnInts :: IO [Int] bsGetLnInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine abc330f :: Int -> Int -> [[Int]] -> Int abc330f n k xys = sat where xm = mkfunc $ IM.fromListWith (+) [(x, 1) | x:_ <- xys] -- X軸について数える ym = mkfunc $ IM.fromListWith (+) [(y, 1) | _:y:_ <- xys] -- Y軸 (_unsat, sat) = binarySearch (\r -> evalFunc xm r + evalFunc ym r <= k) (-1) 1_000_000_001 -- mkfuncのIntMapを関数として計算する evalFunc :: IM.IntMap Int -> Int -> Int evalFunc im x = case (IM.lookupLE x im, IM.lookupGT x im) of (Nothing, _) -> tooBig (_, Nothing) -> 0 (Just (xl,yl), Just (xu,yu)) -> yl + div ((yu - yl) * (x - xl)) (xu - xl) tooBig :: Int tooBig = div maxBound 2 -- 作る幅とコストの関係を表すIntMapを作る mkfunc :: IM.IntMap Int -> IM.IntMap Int mkfunc im = IM.fromList $ loop width 0 wsL accsL wsR accsR where width = fst (IM.findMax im) - fst (IM.findMin im) -- 幅 (rsL, cntsL) = unzip $ IM.toAscList im -- X軸の値リストとカウントリスト relative position wsL = zipWith (-) (tail rsL) rsL -- それぞれ順に押し込む距離 width に変換 accsL = scanl1 (+) cntsL -- 押し込む累積の粒の数 (rsR, cntsR) = unzip $ IM.toDescList im -- 今度は右からの wsR = zipWith (-) rsR (tail rsR) -- 右端からの押し込み距離 accsR = scanl1 (+) cntsR -- 押し込む累積の粒の数 loop wid cost wsL accsL wsR accsR = (wid, cost) : case () of () | wid == 0 -> [] | a1L <= a1R -> loop (wid - w1L) (cost + w1L * a1L) (tail wsL) (tail accsL) wsR accsR | otherwise -> loop (wid - w1R) (cost + w1R * a1R) wsL accsL (tail wsR) (tail accsR) where a1L = head accsL a1R = head accsR w1L = head wsL w1R = head wsR -- @gotoki_no_joe binarySearch :: (Int -> Bool) -> Int -> Int -> (Int, Int) binarySearch prop unsat sat = loop unsat sat where loop a b | ende = (a, b) | prop m = loop a m | True = loop m b where ende = a == m || b == m m = div (a + b) 2 {- WAx7した。satに+1するのを忘れたのが原因か? -}
Submission Info
Submission Time | |
---|---|
Task | F - Minimize Bounding Square |
User | joetheshootingst |
Language | Haskell (GHC 9.4.5) |
Score | 0 |
Code Size | 2591 Byte |
Status | WA |
Exec Time | 860 ms |
Memory | 251248 KB |
Compile Error
app/Main.hs:19:9: warning: [-Wunused-matches] Defined but not used: ‘n’ | 19 | abc330f n k xys = sat | ^ app/Main.hs:48:19: warning: [-Wname-shadowing] This binding for ‘wsL’ shadows the existing binding bound at app/Main.hs:43:5 | 48 | loop wid cost wsL accsL wsR accsR = (wid, cost) : | ^^^ app/Main.hs:48:23: warning: [-Wname-shadowing] This binding for ‘accsL’ shadows the existing binding bound at app/Main.hs:44:5 | 48 | loop wid cost wsL accsL wsR accsR = (wid, cost) : | ^^^^^ app/Main.hs:48:29: warning: [-Wname-shadowing] This binding for ‘wsR’ shadows the existing binding bound at app/Main.hs:46:5 | 48 | loop wid cost wsL accsL wsR accsR = (wid, cost) : | ^^^ app/Main.hs:48:33: warning: [-Wname-shadowing] This binding for ‘accsR’ shadows the existing binding bound at app/Main.hs:47:5 | 48 | loop wid cost wsL accsL wsR accsR = (wid, cost) : | ^^^^^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 525 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | hack_01.txt, hack_02.txt, hack_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt, test_71.txt, test_72.txt, test_73.txt, test_74.txt, test_75.txt, test_76.txt, test_77.txt, test_78.txt, test_79.txt, test_80.txt, test_81.txt, test_82.txt, test_83.txt, test_84.txt, test_85.txt, test_86.txt, test_87.txt, test_88.txt, test_89.txt, test_90.txt, test_91.txt, test_92.txt, test_93.txt, test_94.txt, test_95.txt, test_96.txt, test_97.txt, test_98.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
hack_01.txt | AC | 174 ms | 90292 KB |
hack_02.txt | AC | 164 ms | 90216 KB |
hack_03.txt | WA | 174 ms | 90292 KB |
sample_01.txt | AC | 1 ms | 6972 KB |
sample_02.txt | AC | 1 ms | 6956 KB |
sample_03.txt | AC | 1 ms | 6880 KB |
test_01.txt | AC | 2 ms | 6904 KB |
test_02.txt | AC | 1 ms | 6912 KB |
test_03.txt | AC | 1 ms | 6936 KB |
test_04.txt | AC | 1 ms | 6956 KB |
test_05.txt | AC | 2 ms | 6832 KB |
test_06.txt | AC | 2 ms | 6924 KB |
test_07.txt | AC | 2 ms | 6920 KB |
test_08.txt | AC | 1 ms | 6860 KB |
test_09.txt | AC | 2 ms | 6968 KB |
test_10.txt | AC | 2 ms | 6920 KB |
test_11.txt | AC | 1 ms | 6868 KB |
test_12.txt | AC | 2 ms | 6824 KB |
test_13.txt | AC | 1 ms | 6932 KB |
test_14.txt | AC | 2 ms | 6932 KB |
test_15.txt | AC | 2 ms | 6920 KB |
test_16.txt | AC | 2 ms | 6960 KB |
test_17.txt | AC | 2 ms | 6968 KB |
test_18.txt | AC | 2 ms | 6836 KB |
test_19.txt | AC | 1 ms | 6828 KB |
test_20.txt | AC | 1 ms | 6928 KB |
test_21.txt | AC | 2 ms | 6860 KB |
test_22.txt | AC | 2 ms | 6976 KB |
test_23.txt | AC | 2 ms | 6904 KB |
test_24.txt | AC | 2 ms | 6700 KB |
test_25.txt | AC | 1 ms | 6996 KB |
test_26.txt | AC | 1 ms | 6916 KB |
test_27.txt | AC | 770 ms | 242860 KB |
test_28.txt | AC | 21 ms | 15192 KB |
test_29.txt | AC | 153 ms | 60864 KB |
test_30.txt | AC | 780 ms | 250208 KB |
test_31.txt | AC | 637 ms | 175328 KB |
test_32.txt | AC | 750 ms | 251248 KB |
test_33.txt | AC | 760 ms | 249260 KB |
test_34.txt | AC | 356 ms | 135856 KB |
test_35.txt | AC | 760 ms | 246928 KB |
test_36.txt | AC | 750 ms | 243120 KB |
test_37.txt | AC | 577 ms | 164464 KB |
test_38.txt | AC | 547 ms | 160364 KB |
test_39.txt | AC | 850 ms | 245100 KB |
test_40.txt | AC | 143 ms | 57668 KB |
test_41.txt | AC | 31 ms | 22568 KB |
test_42.txt | AC | 850 ms | 243112 KB |
test_43.txt | AC | 840 ms | 239712 KB |
test_44.txt | AC | 61 ms | 33404 KB |
test_45.txt | AC | 860 ms | 243112 KB |
test_46.txt | AC | 627 ms | 176572 KB |
test_47.txt | AC | 72 ms | 32488 KB |
test_48.txt | AC | 850 ms | 243184 KB |
test_49.txt | AC | 547 ms | 164456 KB |
test_50.txt | AC | 41 ms | 24868 KB |
test_51.txt | AC | 820 ms | 249264 KB |
test_52.txt | AC | 750 ms | 250192 KB |
test_53.txt | AC | 506 ms | 165416 KB |
test_54.txt | AC | 810 ms | 244952 KB |
test_55.txt | AC | 537 ms | 160364 KB |
test_56.txt | AC | 810 ms | 239212 KB |
test_57.txt | AC | 840 ms | 250076 KB |
test_58.txt | AC | 375 ms | 130856 KB |
test_59.txt | AC | 537 ms | 163440 KB |
test_60.txt | AC | 850 ms | 249184 KB |
test_61.txt | AC | 546 ms | 157960 KB |
test_62.txt | AC | 707 ms | 172444 KB |
test_63.txt | AC | 810 ms | 245168 KB |
test_64.txt | AC | 526 ms | 162000 KB |
test_65.txt | AC | 304 ms | 96496 KB |
test_66.txt | AC | 759 ms | 250240 KB |
test_67.txt | AC | 365 ms | 134736 KB |
test_68.txt | AC | 243 ms | 84588 KB |
test_69.txt | AC | 780 ms | 250280 KB |
test_70.txt | AC | 486 ms | 158316 KB |
test_71.txt | AC | 516 ms | 165480 KB |
test_72.txt | AC | 790 ms | 250344 KB |
test_73.txt | AC | 112 ms | 50804 KB |
test_74.txt | AC | 41 ms | 25500 KB |
test_75.txt | AC | 144 ms | 86468 KB |
test_76.txt | AC | 144 ms | 86460 KB |
test_77.txt | WA | 174 ms | 90228 KB |
test_78.txt | WA | 174 ms | 90296 KB |
test_79.txt | WA | 174 ms | 90224 KB |
test_80.txt | WA | 164 ms | 90016 KB |
test_81.txt | WA | 174 ms | 90228 KB |
test_82.txt | WA | 164 ms | 90328 KB |
test_83.txt | AC | 507 ms | 188848 KB |
test_84.txt | AC | 497 ms | 188868 KB |
test_85.txt | AC | 477 ms | 184712 KB |
test_86.txt | AC | 497 ms | 184688 KB |
test_87.txt | AC | 477 ms | 187764 KB |
test_88.txt | AC | 507 ms | 188836 KB |
test_89.txt | AC | 497 ms | 188804 KB |
test_90.txt | AC | 497 ms | 187832 KB |
test_91.txt | AC | 425 ms | 109968 KB |
test_92.txt | AC | 444 ms | 109996 KB |
test_93.txt | AC | 425 ms | 110008 KB |
test_94.txt | AC | 384 ms | 110000 KB |
test_95.txt | AC | 405 ms | 110004 KB |
test_96.txt | AC | 404 ms | 109924 KB |
test_97.txt | AC | 405 ms | 109996 KB |
test_98.txt | AC | 404 ms | 109792 KB |