Task: | Spiraali |
Sender: | wolruso |
Submission time: | 2021-10-10 19:56:35 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | RUNTIME ERROR | 0 |
#2 | RUNTIME ERROR | 0 |
#3 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | RUNTIME ERROR | 0.01 s | 1 | details |
#2 | RUNTIME ERROR | 0.01 s | 2 | details |
#3 | RUNTIME ERROR | 0.01 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:67:38: warning: format '%u' expects argument of type 'unsigned int*', but argument 2 has type 'uint64_t* {aka long unsigned int*}' [-Wformat=] scanf("%u %hu", &size, &testCount); ~~~~~ ^ input/code.cpp:67:38: warning: format '%hu' expects argument of type 'short unsigned int*', but argument 3 has type 'uint64_t* {aka long unsigned int*}' [-Wformat=] input/code.cpp:71:48: warning: format '%u' expects argument of type 'unsigned int*', but argument 2 has type 'uint64_t* {aka long unsigned int*}' [-Wformat=] scanf("%u %u", &tests[i].y, &tests[i].x); ~~~~~~~~~~~ ^ input/code.cpp:71:48: warning: format '%u' expects argument of type 'unsigned int*', but argument 3 has type 'uint64_t* {aka long unsigned int*}' [-Wformat=] input/code.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunus...
Code
#include <stdio.h> #include <stdint.h> struct Test { uint64_t x; uint64_t y; }; uint64_t getValue(uint64_t x, uint64_t y, uint64_t size) { // Quit if invalid coordinates if (x >= size || y >= size) return 0; uint64_t ringDepth, ringSize, ringRelativeX, ringRelativeY, sideRelativeCoord; uint64_t ringStartingValue, sideStartingValue; const uint64_t maxIndx = size - 1; // Calculate the ring depth ringDepth = x; if (y < ringDepth) ringDepth = y; if (maxIndx - x < ringDepth) ringDepth = maxIndx - x; if (maxIndx - y < ringDepth) ringDepth = maxIndx - y; // Calculate the size of the ring and the coordinates relative to it ringSize = size - ringDepth * 2; ringRelativeX = x - ringDepth; ringRelativeY = y - ringDepth; /** * n = ringDepth * o = order of matrix * ringStartingValue = 1 + 4n(o - n) */ // Calculate the starting value of the ring ringStartingValue = 1 + 4 * ringDepth * (size - ringDepth); // Calculate the side of this ring, it's starting value and the coordinate relative to it if (ringRelativeX == 0) { sideStartingValue = ringStartingValue + 0 * (ringSize - 1); sideRelativeCoord = ringRelativeY; } else if (ringRelativeY == ringSize - 1) { sideStartingValue = ringStartingValue + 1 * (ringSize - 1); sideRelativeCoord = ringRelativeX; } else if (ringRelativeX == ringSize - 1) { sideStartingValue = ringStartingValue + 2 * (ringSize - 1); sideRelativeCoord = (ringSize - 1) - ringRelativeY; } else if (ringRelativeY == 0) { sideStartingValue = ringStartingValue + 3 * (ringSize - 1); sideRelativeCoord = (ringSize - 1) - ringRelativeX; } return sideStartingValue + sideRelativeCoord; } int main() { uint64_t size; uint64_t testCount; scanf("%u %hu", &size, &testCount); Test *tests = new Test[testCount]; for (uint64_t i = 0; i < testCount; i++) { scanf("%u %u", &tests[i].y, &tests[i].x); // Map the indices from the range [1, n] to [0, n - 1] tests[i].y--; tests[i].x--; } for (uint64_t i = 0; i < testCount; i++) { printf("%lu\n", getValue(tests[i].x, tests[i].y, size)); } return 0; }
Test details
Test 1
Group: 1
Verdict: RUNTIME ERROR
input |
---|
10 100 1 1 1 2 1 3 1 4 ... |
correct output |
---|
1 36 35 34 33 ... |
user output |
---|
(empty) |
Error:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
Test 2
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 371 263 915 322 946 880 53 738 ... |
correct output |
---|
773533 312166 206053 200080 593922 ... |
user output |
---|
(empty) |
Error:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
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