| Task: | Spiraali |
| Sender: | EeliH |
| Submission time: | 2021-10-04 20:26:05 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 15 |
| #2 | ACCEPTED | 20 |
| #3 | ACCEPTED | 65 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1 | details |
| #2 | ACCEPTED | 0.01 s | 2 | details |
| #3 | ACCEPTED | 0.01 s | 3 | details |
Code
#include <cmath>
#include <iostream>
using namespace std;
int64_t get_layer(int64_t x, int64_t y) {
return max(abs(x), abs(y));
}
int64_t get_offset(int64_t x, int64_t y) {
int64_t layer = get_layer(x, y);
int64_t offset = 4 * layer * layer - 4 * layer + 1;
return offset;
}
int64_t get_strip_i(int64_t x, int64_t y) {
int64_t layer = get_layer(x, y);
int64_t width = 2 * layer + 1;
if(x == layer) {
return (3 * width - 3) - y + layer - 1;
} else if(y == -layer) {
return layer - x - 1;
} else if(x == -layer) {
return (width - 1) + y + layer - 1;
} else if(y == layer) {
return (2 * width - 2) + x + layer - 1;
}
return 1234;
}
int main()
{
int64_t n, t;
cin >> n >> t;
//cout << get_offset(x, y) + get_strip_i(x, y) << endl;
//cout << get_offset(x, y) << endl;
//cout << get_strip_i(x, y) << endl;
for(int64_t i = 0; i < t; i++) {
int64_t x, y;
cin >> y >> x;
// Koordinaatit alkamaan (0,0)
x--;
y--;
int64_t nx, ny;
nx = (int64_t) (n / 2);
ny = (int64_t) ((n - 1) / 2);
x = x - nx;
y = ny - y;
int64_t arvo = n * n - (get_offset(x, y) + get_strip_i(x, y));
//cout << "A " << get_strip_i(x, y) << endl;
//cout << "B " << get_offset(x, y) << endl;
cout << arvo << endl;
//cout << x << " " << y << endl;
}
//cout << "AAAA" << endl;
//cout << get_strip_i(0, -1) << endl;
//cout << get_strip_i(-1, -1) << endl;
//cout << get_strip_i(-1, 0) << endl;
//cout << get_strip_i(-1, 1) << endl;
//cout << get_strip_i(0, 1) << endl;
//cout << get_strip_i(1, 1) << endl;
//cout << get_strip_i(1, 0) << endl;
//cout << get_strip_i(1, -1) << endl;
//cout << "AAAA" << endl;
//cout << get_strip_i(1, -2) << endl;
//cout << get_strip_i(0, -2) << endl;
//cout << get_strip_i(-1, -2) << endl;
//cout << get_strip_i(-2, -2) << endl;
//cout << get_strip_i(-2, -1) << endl;
//cout << get_strip_i(-2, 0) << endl;
//cout << get_strip_i(-2, 1) << endl;
//cout << get_strip_i(-2, 2) << endl;
//cout << get_strip_i(-1, 2) << endl;
//cout << get_strip_i(0, 2) << endl;
//cout << get_strip_i(1, 2) << endl;
//cout << get_strip_i(2, 2) << endl;
//cout << get_strip_i(2, 1) << endl;
//cout << get_strip_i(2, 0) << endl;
//cout << get_strip_i(2, -1) << endl;
//cout << get_strip_i(2, -2) << endl;
}
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 ... Truncated |
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 ... Truncated |
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 93689788375037 ... Truncated |
