Submission #38240789


Source Code Expand

import System.IO
import Data.List
import Control.Monad

theList = [4,5,7,9,11,13,17,19,23]
as = concat $ snd $ mapAccumL step 1 theList
  where
    step b l = (b+l, take (pred l) [succ b..] ++ [b])

main = do
  print 108
  putStrLn $ unwords $ map show as
  hFlush stdout
  bs <- map read . words <$> getLine
  let ans = phase2 bs
  print ans
  
phase2 :: [Int] -> Int
phase2 bs = ans
  where
    bs1 = map (bs !!) $ init $ scanl (+) 0 theList
    rs = zipWith (-) bs1 $ scanl (+) 1 theList
    Just (ans,_) = crt $ zip rs theList

-- @gotoki_no_joe
crt :: [(Int,Int)] -> Maybe (Int,Int)
crt = foldM step1 (0,1)
  where
    step1 (r0,m0) (r1,m1)
      | m0 < m1   = step2 (mod r1 m1) m1 r0 m0
      | otherwise = step2 r0 m0 (mod r1 m1) m1
    step2 r0 m0 r1 m1
      | mod m0 m1 == 0 = if mod r0 m1 == r1 then Just (r0, m0) else Nothing
      | r /= 0         = Nothing
      | otherwise      = Just (r0 + x * m0, m0 * u)
      where
        (g,im) = invGCD m0 m1
        (q, r) = divMod (r1 - r0) g
        u = div m1 g
        x = mod (mod q u * im) u

invGCD :: Int -> Int -> (Int, Int)
invGCD a b
  | a1 == 0 = (b, 0)
  | otherwise = loop b a1 0 1
  where
    a1 = mod a b
    loop s 0 m0 m1 = (s, if m0 < 0 then m0 + div b s else m0)
    loop s t m0 m1 = loop t (s - t * u) m1 (m0 - m1 * u)
      where
        u = div s t

Submission Info

Submission Time
Task F - Guess The Number 2
User joetheshootingst
Language Haskell (GHC 8.8.3)
Score 500
Code Size 1380 Byte
Status AC
Exec Time 9 ms
Memory 4080 KiB

Compile Error

Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 30
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 9 ms 3928 KiB
01_test_01.txt AC 6 ms 3956 KiB
01_test_02.txt AC 8 ms 3860 KiB
01_test_03.txt AC 6 ms 3928 KiB
01_test_04.txt AC 8 ms 3808 KiB
01_test_05.txt AC 6 ms 3936 KiB
01_test_06.txt AC 7 ms 4040 KiB
01_test_07.txt AC 7 ms 3948 KiB
01_test_08.txt AC 7 ms 3936 KiB
01_test_09.txt AC 6 ms 4036 KiB
01_test_10.txt AC 6 ms 3928 KiB
01_test_11.txt AC 6 ms 3932 KiB
01_test_12.txt AC 8 ms 3960 KiB
01_test_13.txt AC 5 ms 3956 KiB
01_test_14.txt AC 7 ms 3960 KiB
01_test_15.txt AC 6 ms 3976 KiB
01_test_16.txt AC 8 ms 3980 KiB
01_test_17.txt AC 8 ms 3960 KiB
01_test_18.txt AC 7 ms 3960 KiB
01_test_19.txt AC 6 ms 3916 KiB
01_test_20.txt AC 8 ms 4080 KiB
01_test_21.txt AC 7 ms 3936 KiB
01_test_22.txt AC 7 ms 3956 KiB
01_test_23.txt AC 7 ms 3852 KiB
01_test_24.txt AC 9 ms 3980 KiB
01_test_25.txt AC 7 ms 3844 KiB
01_test_26.txt AC 9 ms 3928 KiB
01_test_27.txt AC 8 ms 4076 KiB
01_test_28.txt AC 8 ms 3980 KiB
01_test_29.txt AC 5 ms 3936 KiB