CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:funkar
Submission time:2017-10-09 22:37:41 +0300
Language:Haskell
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.05 s1details
#20.06 s2details
#30.06 s3details

Compiler report

input/code.hs:6:1: Warning:
    Top-level binding with no type signature: c :: [Int]

input/code.hs:7:1: Warning:
    Top-level binding with no type signature: csum :: [Int]

input/code.hs:24:1: Warning:
    Top-level binding with no type signature: main :: IO ()

input/code.hs:28:1: Warning:
    Top-level binding with no type signature: loop :: IO ()

Code

import Data.List

findLog :: Int -> Int
valueOf :: Int -> Int
champ :: Int -> Char
c = [9*n*10^(n-1) | n <- [1..17]]
csum = [1 + (sum $ take n c) | n <- [1..17]]
findLog x = maybe 0 id $ findIndex (>=x+1) csum
-- what is the log(10) of the decimal number at champernowne's constant index x
valueOf x
  | x <= 10 = x
  | x == 11 = 10
  -- below formula doesn't work properly for small x, but their value is straightforward
  | otherwise = ((x-csum !! (b-1)) `div` (b+1)) + 10^b
  -- find the decimal number to which index x in champernowne's constant belongs to
  where b = findLog x
champ x
  | x <= 10 = show(x) !! 0
  -- special cases
  | otherwise = show(valueOf x) !! ((x - csum !! (b-1)) `mod` (b+1))
  -- finally find the number at index x
  where b = findLog x

main = do
  _ <- getLine
  loop

loop = do
  z <- getLine
  if null z then return()
    else do
  print $ champ (read z)
  loop

Test details

Test 1

Group: 1

Verdict:

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
'0'
'1'
'7'
'7'
'6'
...

Error:
code: <stdin>: hGetLine: end of file

Test 2

Group: 2

Verdict:

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
'1'
'2'
'3'
'2'
'2'
...

Error:
code: <stdin>: hGetLine: end of file

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
'7'
'2'
'2'
'0'
'9'
...

Error:
code: <stdin>: hGetLine: end of file