Submission #188254


Source Code Expand

{-# LANGUAGE CPP #-}
#ifndef HDEVTOOLS
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
#endif
{-# LANGUAGE BangPatterns, ViewPatterns, OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as S
import qualified Data.Vector as V

main :: IO ()
main = do
  [n, d] <- map readInt . S.words <$> S.getLine
  [x, y] <- map readInt . S.words <$> S.getLine
  print $ solve n d x y

solve :: Int -> Int -> Int -> Int -> Double
solve n d x y = fromMaybe 0 $ do
  (x', 0) <- return $ divMod x d
  (y', 0) <- return $ divMod y d
  guard $ abs x' + abs y' <= n
  return $! solveSimple n x' y'

solveSimple :: Int -> Int -> Int -> Double
solveSimple n x y = realToFrac $
  (fromIntegral (count n x y) / (4^n) :: Rational)

count :: Int -> Int -> Int -> Integer
count n x y = sum $ do
  u <- [0 .. n]
  let !d = u - x
  guard $ d >= 0
  let !remaining = n - u - d
  guard $ remaining >= 0
  (r, 0) <- return $ divMod (y + remaining) 2
  guard $ r >= 0
  let !l = r - y
  guard $ l >= 0
  return $ fact n `div` fact u `div` fact d `div` fact l `div` fact r

fact :: Int -> Integer
fact k = factTable V.! k

factTable :: V.Vector Integer
factTable = V.scanl (*) 1 $ V.enumFromN 1 1001

readInt :: S.ByteString -> Int
readInt s = case S.readInt s of
  Just (r, "") -> r
  _ -> error $ "not an integer: " ++ show s

Submission Info

Submission Time
Task D - 大ジャンプ
User mkotha
Language Haskell (GHC 7.4.1)
Score 101
Code Size 1420 Byte
Status AC
Exec Time 43 ms
Memory 2848 KB

Judge Result

Set Name part1 part2 All
Score / Max Score 90 / 90 10 / 10 1 / 1
Status
AC × 23
AC × 36
AC × 68
Set Name Test Cases
part1 test_1_151403858_0_0AB.txt, test_1_1_0_1AB.txt, test_1_1_2_0AB.txt, test_1_200416616_-430405070_-79858930AB.txt, test_1_320861287_0_0AB.txt, test_1_445441131_0_0AB.txt, test_2_91743015_0_183486030AB.txt, test_3_165357536_496072608_0AB.txt, test_3_357154050_-106436394_768502001AB.txt, test_3_721501125_-568833455_353553641AB.txt, test_3_893846474_0_0AB.txt, test_4_291388018_-291388018_0AB.txt, test_5_318547875_955643625_-637095750AB.txt, test_5_704387671_-704387671_0AB.txt, test_5_82323965_639854915_-688317394AB.txt, test_6_187422602_374845204_-374845204AB.txt, test_6_346164451_0_0AB.txt, test_6_99058019_194123640_-837769837AB.txt, test_7_166330212_166330212_-332660424AB.txt, test_7_89698746_448493730_-179397492AB.txt, test_8_10000000_-40000000_-40000000AB.txt, test_8_10000000_0_80000000AB.txt, test_8_10000000_80000000_0AB.txt
part2 test_10_227248639_454497278_0B.txt, test_11_692637325_-181424149_-938839075B.txt, test_13_260236679_-780710037_-520473358B.txt, test_13_269280357_807841071_269280357B.txt, test_13_96859935_0_-581159610B.txt, test_16_40374395_-40374395_-565241530B.txt, test_1_151403858_0_0AB.txt, test_1_1_0_1AB.txt, test_1_1_2_0AB.txt, test_1_200416616_-430405070_-79858930AB.txt, test_1_320861287_0_0AB.txt, test_1_445441131_0_0AB.txt, test_21_304856339_609712678_914569017B.txt, test_26_214390232_-857560928_428780464B.txt, test_2_91743015_0_183486030AB.txt, test_30_10000000_-300000000_0B.txt, test_30_10000000_0_300000000B.txt, test_30_10000000_150000000_-150000000B.txt, test_30_54228128_0_813421920B.txt, test_3_165357536_496072608_0AB.txt, test_3_357154050_-106436394_768502001AB.txt, test_3_721501125_-568833455_353553641AB.txt, test_3_893846474_0_0AB.txt, test_4_291388018_-291388018_0AB.txt, test_5_318547875_955643625_-637095750AB.txt, test_5_704387671_-704387671_0AB.txt, test_5_82323965_639854915_-688317394AB.txt, test_6_187422602_374845204_-374845204AB.txt, test_6_346164451_0_0AB.txt, test_6_99058019_194123640_-837769837AB.txt, test_7_166330212_166330212_-332660424AB.txt, test_7_89698746_448493730_-179397492AB.txt, test_8_10000000_-40000000_-40000000AB.txt, test_8_10000000_0_80000000AB.txt, test_8_10000000_80000000_0AB.txt, test_9_283198156_849594468_849594468B.txt
All test_1000_1000000_-500000000_500000000.txt, test_1000_1000000_0_-1000000000.txt, test_1000_1000000_1000000000_0.txt, test_1000_150305_97998860_-32315575.txt, test_1000_1_0_0.txt, test_1000_1_2_0.txt, test_1000_1_2_2.txt, test_1000_3308678_-800700076_-350719868.txt, test_1000_3608549_811923525_689232859.txt, test_1000_3728577_-145414503_-969430020.txt, test_1000_537976_11297496_224335992.txt, test_10_227248639_454497278_0B.txt, test_11_692637325_-181424149_-938839075B.txt, test_130_95365311_-667557177_-286095933.txt, test_131_18204705_-145637640_0.txt, test_13_260236679_-780710037_-520473358B.txt, test_13_269280357_807841071_269280357B.txt, test_13_96859935_0_-581159610B.txt, test_16_40374395_-40374395_-565241530B.txt, test_1_151403858_0_0AB.txt, test_1_1_0_1AB.txt, test_1_1_2_0AB.txt, test_1_200416616_-430405070_-79858930AB.txt, test_1_320861287_0_0AB.txt, test_1_445441131_0_0AB.txt, test_210_28974130_0_260767170.txt, test_217_321156_24407856_22480920.txt, test_21_304856339_609712678_914569017B.txt, test_26_214390232_-857560928_428780464B.txt, test_289_421462830_-487186374_-417635361.txt, test_2_91743015_0_183486030AB.txt, test_30_10000000_-300000000_0B.txt, test_30_10000000_0_300000000B.txt, test_30_10000000_150000000_-150000000B.txt, test_30_54228128_0_813421920B.txt, test_339_4475128_957677392_281933064.txt, test_3_165357536_496072608_0AB.txt, test_3_357154050_-106436394_768502001AB.txt, test_3_721501125_-568833455_353553641AB.txt, test_3_893846474_0_0AB.txt, test_480_402960_-131767920_-34654560.txt, test_4_291388018_-291388018_0AB.txt, test_507_3516183_-879045750_-253165176.txt, test_515_8606048_-25818144_8606048.txt, test_522_2286376_-230923976_-18291008.txt, test_5_318547875_955643625_-637095750AB.txt, test_5_704387671_-704387671_0AB.txt, test_5_82323965_639854915_-688317394AB.txt, test_676_198114948_0_792459792.txt, test_688_151937211_-286341114_10198771.txt, test_6_187422602_374845204_-374845204AB.txt, test_6_346164451_0_0AB.txt, test_6_99058019_194123640_-837769837AB.txt, test_71_367604060_367604060_0.txt, test_752_120973200_0_-725839200.txt, test_772_881340073_0_0.txt, test_777_125719576_-499451637_822057459.txt, test_7_166330212_166330212_-332660424AB.txt, test_7_89698746_448493730_-179397492AB.txt, test_839_166155061_0_-332310122.txt, test_839_923157_923157_564972084.txt, test_849_415705_290993500_0.txt, test_873_418406_2928842_322172620.txt, test_8_10000000_-40000000_-40000000AB.txt, test_8_10000000_0_80000000AB.txt, test_8_10000000_80000000_0AB.txt, test_981_159373724_-637494896_-159373724.txt, test_9_283198156_849594468_849594468B.txt
Case Name Status Exec Time Memory
sample_01.txt AC 27 ms 1444 KB
sample_02.txt AC 27 ms 1184 KB
sample_03.txt AC 27 ms 1440 KB
test_1000_1000000_-500000000_500000000.txt AC 30 ms 2844 KB
test_1000_1000000_0_-1000000000.txt AC 30 ms 2836 KB
test_1000_1000000_1000000000_0.txt AC 30 ms 2596 KB
test_1000_150305_97998860_-32315575.txt AC 28 ms 1560 KB
test_1000_1_0_0.txt AC 42 ms 2844 KB
test_1000_1_2_0.txt AC 43 ms 2836 KB
test_1000_1_2_2.txt AC 43 ms 2844 KB
test_1000_3308678_-800700076_-350719868.txt AC 39 ms 2836 KB
test_1000_3608549_811923525_689232859.txt AC 39 ms 2840 KB
test_1000_3728577_-145414503_-969430020.txt AC 28 ms 1820 KB
test_1000_537976_11297496_224335992.txt AC 37 ms 2848 KB
test_10_227248639_454497278_0B.txt AC 27 ms 1432 KB
test_11_692637325_-181424149_-938839075B.txt AC 26 ms 1188 KB
test_130_95365311_-667557177_-286095933.txt AC 28 ms 1572 KB
test_131_18204705_-145637640_0.txt AC 27 ms 1436 KB
test_13_260236679_-780710037_-520473358B.txt AC 27 ms 1432 KB
test_13_269280357_807841071_269280357B.txt AC 26 ms 1184 KB
test_13_96859935_0_-581159610B.txt AC 27 ms 1180 KB
test_16_40374395_-40374395_-565241530B.txt AC 26 ms 1180 KB
test_1_151403858_0_0AB.txt AC 26 ms 1176 KB
test_1_1_0_1AB.txt AC 28 ms 1576 KB
test_1_1_2_0AB.txt AC 26 ms 1308 KB
test_1_200416616_-430405070_-79858930AB.txt AC 26 ms 1176 KB
test_1_320861287_0_0AB.txt AC 25 ms 1180 KB
test_1_445441131_0_0AB.txt AC 26 ms 1172 KB
test_210_28974130_0_260767170.txt AC 28 ms 1432 KB
test_217_321156_24407856_22480920.txt AC 28 ms 1440 KB
test_21_304856339_609712678_914569017B.txt AC 28 ms 1440 KB
test_26_214390232_-857560928_428780464B.txt AC 29 ms 1516 KB
test_289_421462830_-487186374_-417635361.txt AC 26 ms 1180 KB
test_2_91743015_0_183486030AB.txt AC 27 ms 1440 KB
test_30_10000000_-300000000_0B.txt AC 29 ms 1436 KB
test_30_10000000_0_300000000B.txt AC 29 ms 1496 KB
test_30_10000000_150000000_-150000000B.txt AC 27 ms 1580 KB
test_30_54228128_0_813421920B.txt AC 26 ms 1308 KB
test_339_4475128_957677392_281933064.txt AC 29 ms 1700 KB
test_3_165357536_496072608_0AB.txt AC 29 ms 1392 KB
test_3_357154050_-106436394_768502001AB.txt AC 26 ms 1184 KB
test_3_721501125_-568833455_353553641AB.txt AC 25 ms 1324 KB
test_3_893846474_0_0AB.txt AC 26 ms 1180 KB
test_480_402960_-131767920_-34654560.txt AC 29 ms 1556 KB
test_4_291388018_-291388018_0AB.txt AC 26 ms 1312 KB
test_507_3516183_-879045750_-253165176.txt AC 27 ms 1564 KB
test_515_8606048_-25818144_8606048.txt AC 27 ms 1564 KB
test_522_2286376_-230923976_-18291008.txt AC 28 ms 1568 KB
test_5_318547875_955643625_-637095750AB.txt AC 26 ms 1556 KB
test_5_704387671_-704387671_0AB.txt AC 27 ms 1436 KB
test_5_82323965_639854915_-688317394AB.txt AC 26 ms 1184 KB
test_676_198114948_0_792459792.txt AC 33 ms 2464 KB
test_688_151937211_-286341114_10198771.txt AC 26 ms 1180 KB
test_6_187422602_374845204_-374845204AB.txt AC 30 ms 1380 KB
test_6_346164451_0_0AB.txt AC 27 ms 1428 KB
test_6_99058019_194123640_-837769837AB.txt AC 28 ms 1184 KB
test_71_367604060_367604060_0.txt AC 28 ms 1628 KB
test_752_120973200_0_-725839200.txt AC 34 ms 2460 KB
test_772_881340073_0_0.txt AC 34 ms 2456 KB
test_777_125719576_-499451637_822057459.txt AC 26 ms 1180 KB
test_7_166330212_166330212_-332660424AB.txt AC 28 ms 1432 KB
test_7_89698746_448493730_-179397492AB.txt AC 28 ms 1392 KB
test_839_166155061_0_-332310122.txt AC 27 ms 1696 KB
test_839_923157_923157_564972084.txt AC 31 ms 2652 KB
test_849_415705_290993500_0.txt AC 27 ms 1568 KB
test_873_418406_2928842_322172620.txt AC 31 ms 2588 KB
test_8_10000000_-40000000_-40000000AB.txt AC 27 ms 1436 KB
test_8_10000000_0_80000000AB.txt AC 27 ms 1432 KB
test_8_10000000_80000000_0AB.txt AC 26 ms 1432 KB
test_981_159373724_-637494896_-159373724.txt AC 42 ms 2844 KB
test_9_283198156_849594468_849594468B.txt AC 27 ms 1244 KB