CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:ZakkeX
Submission time:2021-10-04 14:06:24 +0300
Language:Haskell
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED20
#3ACCEPTED65
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1details
#2ACCEPTED0.01 s2details
#3ACCEPTED0.01 s3details

Compiler report

input/code.hs:1:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature: main :: IO ()
  |
1 | main = do
  | ^^^^

input/code.hs:2:8: warning: [-Wunused-matches]
    Defined but not used: `t'
  |
2 |     [n,t] <- map read . words <$> getLine
  |        ^

input/code.hs:2:18: warning: [-Wtype-defaults]
    * Defaulting the following constraints to type `Integer'
        (Read a0) arising from a use of `read' at input/code.hs:2:18-21
        (Show a0) arising from a use of `print' at input/code.hs:3:12-16
        (Ord a0) arising from a use of `luku' at input/code.hs:3:20-25
        (Num a0) arising from a use of `luku' at input/code.hs:3:20-25
    * In the first argument of `map', namely `read'
      In the first argument of `(.)', namely `map read'
      In the first argument of `(<$>)', namely `map read . words'
  |
2 |     [n,t] <- map read . words <$> getLine
  |                  ^^^^

input/code.hs:5:1: warning: [-Wmissing-signatures]
    Top-level binding

Code

main = do
    [n,t] <- map read . words <$> getLine
    mapM_ (print . luku n . (\[y,x] -> (x, y)) . map  read . words) . lines =<< getContents

syvyys n (x, y) = min (syvyys' n x) (syvyys' n y)
    where syvyys' n x = min (x-1) $ abs (n-x)

kuori n (x, y) = (x - n, y - n)

luku n p = let k = syvyys n p in n^2 - (n - 2*k)^2 + reunapituus (n - 2*k) (kuori k p)

reunapituus n (x, y)
  | x == 1 = y
  | y == n = n - 1 + x
  | x == n = 2 * (n - 1) + abs (n-y) + 1
  | y == 1 = 3 * (n - 1) + abs (n-x) + 1
  | otherwise = error "Spiraalia ei ole kuorittu tarpeeksi!"

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
10 100
1 1
1 2
1 3
1 4
...

correct output
1
36
35
34
33
...

user output
1
36
35
34
33
...

Test 2

Group: 2

Verdict: ACCEPTED

input
1000 1000
371 263
915 322
946 880
53 738
...

correct output
773533
312166
206053
200080
593922
...

user output
773533
312166
206053
200080
593922
...

Test 3

Group: 3

Verdict: ACCEPTED

input
1000000000 1000
177757853 827347032
409613589 419171337
739269360 256524697
328695530 896842209
...

correct output
571375684522141210
967321186816598569
762879105851175000
370065046779516790
936897883750373771
...

user output
571375684522141210
967321186816598569
762879105851175000
370065046779516790
936897883750373771
...