CSES - Datatähti 2018 alku - Results
Submission details
Task:Merkkijono
Sender:FSMnArmosta
Submission time:2017-10-08 15:39:42 +0300
Language:Haskell
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.07 sdetails
#20.07 sdetails
#30.07 sdetails
#40.04 sdetails
#50.04 sdetails
#60.05 sdetails
#70.04 sdetails
#80.04 sdetails
#90.05 sdetails
#100.05 sdetails

Compiler report

input/code.hs:4:1: Warning:
    Top-level binding with no type signature:
      combinations :: forall a a1.
                      (Integral a, Num a1) =>
                      a1 -> a1 -> a1 -> a -> a1

input/code.hs:4:20: Warning: Defined but not used: `potential0'

input/code.hs:4:31: Warning: Defined but not used: `potential1'

input/code.hs:12:1: Warning:
    Top-level binding with no type signature:
      startingPoint :: forall a a1 b.
                       (Integral b, Num a, Num a1, Ord a) =>
                       a -> a -> b -> a1

input/code.hs:12:41: Warning:
    Defaulting the following constraint(s) to type `Integer'
      (Integral a0)
        arising from a use of `combinations' at input/code.hs:12:41-52
      (Num a0) arising from the literal `1' at input/code.hs:12:68
    In the first argument of `(>)', namely
      `combinations tentative 0 1 1'
    In the expression: combinations tentative 0 1 1 > target
    In the expression:
      if combinations tentative 0 1...

Code

import Numeric (showIntAtBase)
import Data.Char (intToDigit)

combinations soFar potential0 potential1 0 = soFar
combinations soFar potential0 potential1 bitstring =
    if bit == 0
        then combinations (soFar + potential0) potential0 (potential1 + potential0) rest
        else combinations (soFar + potential1) (potential0 + potential1) potential1 rest
    where bit = bitstring `rem` 2
          rest = bitstring `div` 2

startingPoint current target layer = if combinations tentative 0 1 1 > target then 2^(layer-1) else startingPoint tentative target (layer + 1)
    where tentative = if combinations (current * 2 + 1) 0 1 1 > combinations (current * 2) 0 1 1 then current * 2 + 1 else current * 2

search current target = if combinations 0 1 1 current == target then current else search (current + 1) target

main :: IO ()
main = do
    num <- getLine
    let target = read num :: Int
    putStrLn (showIntAtBase 2 intToDigit (search (startingPoint 1 target 1) target) "")

Test details

Test 1

Verdict:

input
ABABABABABABABABABABABABABABAB...

correct output
ABABABABABABABABABABABABABABAB...

user output
(empty)

Error:
code: Prelude.read: no parse

Test 2

Verdict:

input
AABBAABBAABBAABBAABBAABBAABBAA...

correct output
(empty)

user output
(empty)

Error:
code: Prelude.read: no parse

Test 3

Verdict:

input
ABABABABABABABABABABABABABABAB...

correct output
(empty)

user output
(empty)

Error:
code: Prelude.read: no parse

Test 4

Verdict:

input
BBABABBBBBAABBBABABABBBBAAABAB...

correct output
BAB

user output
(empty)

Error:
code: Prelude.read: no parse

Test 5

Verdict:

input
ACDCBBACDBBBACAACBBDBADBAABABA...

correct output
ACDCACDADBADABACACDCADADABABCA...

user output
(empty)

Error:
code: Prelude.read: no parse

Test 6

Verdict:

input
EETFHIJOGACDHMGVFJCMETMZDEITTR...

correct output
TFHIJOGACDHMGVFJCMETMZDEIROTET...

user output
(empty)

Error:
code: Prelude.read: no parse

Test 7

Verdict:

input
GOONLAHLYPRFCZKIKSJWAWWYJJPCDB...

correct output
GNLAHLYPRFCZKIKSJWAYPCDNWYMRCE...

user output
(empty)

Error:
code: Prelude.read: no parse

Test 8

Verdict:

input
PISHWMOTCDDZFRMYMOMYDYYGJZIQHS...

correct output
PISHWMOTCZFRMYMOMYDGJZIQHSVAOK...

user output
(empty)

Error:
code: Prelude.read: no parse

Test 9

Verdict:

input
QUVVTPXAMWWODFXRONJODPGBTCISGM...

correct output
QUTPXAMODFXRONJODPGBTCISGMVRBW...

user output
(empty)

Error:
code: Prelude.read: no parse

Test 10

Verdict:

input
POXHAHYEZTLYNFSLABODMRNKDSKROZ...

correct output
POXHAHYEZTLYNFSLABODMRNKDSKROZ...

user output
(empty)

Error:
code: Prelude.read: no parse