CSES - Harjoituskisa 7.1.2018 - Results
Submission details
Task:Inversiot
Sender:FSMnArmosta
Submission time:2018-01-07 20:35:01 +0200
Language:Haskell
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED11
#2ACCEPTED35
#3ACCEPTED54
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.05 s1details
#3ACCEPTED0.05 s1details
#4ACCEPTED0.07 s1details
#5ACCEPTED0.04 s1details
#6ACCEPTED0.04 s2details
#7ACCEPTED0.04 s2details
#8ACCEPTED0.05 s2details
#9ACCEPTED0.05 s2details
#10ACCEPTED0.05 s2details
#11ACCEPTED0.29 s3details
#12ACCEPTED0.33 s3details
#13ACCEPTED0.29 s3details
#14ACCEPTED0.31 s3details
#15ACCEPTED0.26 s3details

Compiler report

input/code.hs:2:1: Warning:
    Top-level binding with no type signature:
      deltaAfterIterations :: forall a. Integral a => a -> a -> a

input/code.hs:2:64: Warning:
    Defaulting the following constraint(s) to type `Integer'
      (Integral b0) arising from a use of `^' at input/code.hs:2:64
      (Num b0) arising from the literal `2' at input/code.hs:2:65
    In the first argument of `(+)', namely `iterations ^ 2'
    In the first argument of `div', namely
      `(iterations ^ 2 + iterations)'
    In the second argument of `(-)', namely
      `((iterations ^ 2 + iterations) `div` 2)'

input/code.hs:6:20: Warning:
    Defaulting the following constraint(s) to type `Double'
      (Floating a0) arising from a use of `sqrt' at input/code.hs:6:20-23
      (Fractional a0) arising from a use of `/' at input/code.hs:5:75
      (Num a0)
        arising from a use of `fromIntegral' at input/code.hs:6:25-36
      (RealFrac a0)
        arising from a use of `floor' at input/code.hs:5:30-34...

Code

deltaAfterIterations iterations n = iterations*n - ((iterations^2 + iterations) `div` 2)

iterationsForDelta :: Int -> Int -> Int
iterationsForDelta delta n = floor (((fromIntegral (2*n - 1)) - floating) / 2)
  where floating = sqrt(fromIntegral (4*(n^2) - 4*n + 1 - 8*delta))

main = do
  [n, k] <- do
    l <- getLine
    return ((map read) (words l)) :: IO [Int]
  let even = (deltaAfterIterations (iterationsForDelta k n) n) == k
  let movedFromBeginning = iterationsForDelta k n
  if even
    then do
      putStr (unwords (map (show) [(movedFromBeginning+1)..n]))
      putStr " "
      putStrLn (unwords (map (\x -> show (movedFromBeginning - x + 1)) [1..movedFromBeginning]))
    else do
      let index = k - (deltaAfterIterations (iterationsForDelta k n) n)
      putStr (unwords (map (show) ((take index [(movedFromBeginning+2)..n]))))
      putStr " "
      putStr (show (movedFromBeginning+1))
      putStr " "
      putStr (unwords (map (show) (drop index [(movedFromBeginning+2)..n])))
      putStr " "
      putStrLn (unwords (map (\x -> show (movedFromBeginning - x + 1)) [1..(movedFromBeginning)]))
  

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
5 0

correct output
1 2 3 4 5 

user output
1 2 3 4 5 

Test 2

Group: 1

Verdict: ACCEPTED

input
5 1

correct output
2 1 3 4 5 

user output
2 1 3 4 5 

Test 3

Group: 1

Verdict: ACCEPTED

input
5 2

correct output
3 1 2 4 5 

user output
2 3 1 4 5 

Test 4

Group: 1

Verdict: ACCEPTED

input
5 4

correct output
5 1 2 3 4 

user output
2 3 4 5 1

Test 5

Group: 1

Verdict: ACCEPTED

input
5 10

correct output
5 4 3 2 1 

user output
5 4 3 2 1

Test 6

Group: 2

Verdict: ACCEPTED

input
100 0

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 7

Group: 2

Verdict: ACCEPTED

input
100 1

correct output
2 1 3 4 5 6 7 8 9 10 11 12 13 ...

user output
2 1 3 4 5 6 7 8 9 10 11 12 13 ...

Test 8

Group: 2

Verdict: ACCEPTED

input
100 990

correct output
100 99 98 97 96 95 94 93 92 91...

user output
12 13 14 15 16 17 18 19 20 21 ...

Test 9

Group: 2

Verdict: ACCEPTED

input
100 1980

correct output
100 99 98 97 96 95 94 93 92 91...

user output
24 25 26 27 28 29 30 31 32 33 ...

Test 10

Group: 2

Verdict: ACCEPTED

input
100 4950

correct output
100 99 98 97 96 95 94 93 92 91...

user output
100 99 98 97 96 95 94 93 92 91...

Test 11

Group: 3

Verdict: ACCEPTED

input
1000000 0

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 12

Group: 3

Verdict: ACCEPTED

input
1000000 1

correct output
2 1 3 4 5 6 7 8 9 10 11 12 13 ...

user output
2 1 3 4 5 6 7 8 9 10 11 12 13 ...

Test 13

Group: 3

Verdict: ACCEPTED

input
1000000 99999900000

correct output
1000000 999999 999998 999997 9...

user output
105574 105575 105576 105577 10...

Test 14

Group: 3

Verdict: ACCEPTED

input
1000000 199999800000

correct output
1000000 999999 999998 999997 9...

user output
225405 225406 225407 225408 22...

Test 15

Group: 3

Verdict: ACCEPTED

input
1000000 499999500000

correct output
1000000 999999 999998 999997 9...

user output
1000000 999999 999998 999997 9...