Task: | Spiraali |
Sender: | Sahari Kempo |
Submission time: | 2021-10-10 21:24:27 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 35 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 15 |
#2 | ACCEPTED | 20 |
#3 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1 | details |
#2 | ACCEPTED | 0.02 s | 2 | details |
#3 | RUNTIME ERROR | 0.01 s | 3 | details |
Code
#include <math.h> #include <iostream> #include <vector> # define L long long using namespace std; int main() { L n, t, x = 1, i, y; int p = 0; cin >> n >> t; vector<vector<L>> m(1); m.resize(n); y = m.size(); for (i = 0; i < y; i++) m[i].resize(n); int b = 0; n -= 1; while (x <= pow(n + 1, 2)) { for (i = 0; i <= n; i++) { if (b == 0) { if (m[i][p] == 0) m[i][p] = x; else x--; } else if (b == 1) { if (m[n - p][i] == 0) m[n - p][i] = x; else x--; } else if (b == 2) { if (m[n - i][n - p] == 0) m[n - i][n - p] = x; else x--; } else if (b == 3) { if (m[p][n - i] == 0) m[p][n - i] = x; else x--; } x++; } if (b == 3) { b = 0; p++; } else b++; if (p > n) p = n; } vector<L> l; y = 0; for (i = 0; i < t; i++) { cin >> x >> y; l.push_back(m[x - 1][y - 1]); } for (i = 0; i < t; i++) { cout << l[i] << "\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 ... 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: RUNTIME ERROR
input |
---|
1000000000 1000 177757853 827347032 409613589 419171337 739269360 256524697 328695530 896842209 ... |
correct output |
---|
571375684522141210 967321186816598569 762879105851175000 370065046779516790 936897883750373771 ... |
user output |
---|
(empty) |
Error:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc