CSES - DatatÃ¤hti 2022 alku - Results
 Task: Spiraali (Spiral) Sender: masuman Submission time: 2021-10-07 00:09:31 Language: C++11 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.cpp: In function 'll ring(ll, ll, ll)':
input/code.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
input/code.cpp: In function 'll runningNumber(ll, ll, ll)':
input/code.cpp:73:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^```

### Code

```#include <bits/stdc++.h>

//g++ -std=c++11 -O2 -Wall _____ -o test
using namespace std;

using ll = long long;

ll r(ll y, ll x, ll n, vector<ll> xx){
return max(abs(xx[0]-y), abs(xx[1]-x));
}

ll ring(ll y, ll x, ll n){
vector<ll> nw = {n/2, n/2};
vector<ll> ne = {n/2, (n/2)+1};
vector<ll> se = {(n/2)+1,(n/2)+1};
vector<ll> sw = {(n/2)+1,n/2};

if ((x <= n/2) && (y <= n/2)){
return r(y,x,n, nw);
}
if ((x > n/2) && (y <= n/2)){
return r(y,x,n, ne);
}
if ((x <= n/2) && (y > n/2)){
return r(y,x,n, sw);
}
if ((x > n/2) && (y > n/2)){
return r(y,x,n, se);
}
}

vector<ll> ringCount(ll y, ll x, ll n){
ll yNew = y - ((n/2)-1-ring(y,x,n));
ll xNew = x - ((n/2)-1-ring(y,x,n));
vector<ll> result = {yNew, xNew};
return result;
}

ll runningNumber(ll y, ll x, ll p){

p = (p+1)*2;

if (y == p && x == 1){
return p;
}
if (y == p && x == p){
return (2*p - 1);
}
if (y==1 && x==1){
return 1;
}
if (y==1 && x==p){
return (3*p-2);
}

if(y==1){
return (4*p-2-x);
}
if(y==p){
return(x+p-1);
}
if(x==1){
return y;
}
if(x==p){
return (3*p-1-y);
}

}

ll s(ll n,ll p){
return (4*p*(n-p));
}

ll f(ll y,ll x,ll n){
vector<ll> k = ringCount(y,x,n);
ll g = ring(y,x,n);
ll p = runningNumber(k[0], k[1], g);
ll d = (n/2)-g-1;
ll e = s(n,d);
return e+p;
}
int main(){

ll t;
ll n;

cin >> n >> t;
ll x, y;
for(ll i = 1; i <= t; i++){
cin >> y >> x;
cout << f(y,x,n) << "\n";
}

}```

### 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
...