Task: | Spiraali |
Sender: | valk |
Submission time: | 2021-10-14 23:30:59 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 35 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 15 |
#2 | ACCEPTED | 20 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1 | details |
#2 | ACCEPTED | 0.01 s | 2 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
// TaskCSpiral.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include <map> #include <string> using namespace std; int main() { int size; //size int tests; //tests cin >> size; cin >> tests; for (int i = 0; i < tests; i++) { int x; int y; cin >> y; cin >> x; int layer = 0; if (x > y && y <= size / 2 && x + y - 1 < size) { layer = y; } else if ((x <= size / 2 && size - y >= x) || x > y) { layer = x; } else { layer = y; } //System.out.println("og layer " + layer); if (layer > size / 2) layer = size / 2 - (layer - size / 2) + 1; int width = (size - (layer - 1) * 2); //System.out.println("width " + width + " layer " + layer); int tArea = 0; if (layer > size / 4) { //more than half in tArea = size * size; for (int l = size/2; l >= layer; l--) { tArea -= ((size - (l - 1) * 2) * 4 - 4); //cout << "layer " << layer << " subtracting " << to_string(((size - (l - 1) * 2) * 4 - 4)) << "\n"; //cout << "area now " << tArea << "\n"; //int tArea2 = 0; //for (int l = 1; l < layer; l++) { // tArea2 += (size - (layer - 1 - l) * 2) * 4 - 4; //} //cout << "wouldve been " << tArea2 << "\n"; } } else { //more out than half for (int l = 1; l < layer; l++) { tArea += (size - (layer - 1 - l) * 2) * 4 - 4; } } if (x == layer) { //left d tArea += (y - (layer - 1)); //System.out.println("left"); } else if (x == size - layer + 1 && x != y) {//right d tArea += width * 3 - (layer + y - (layer - 1) * 2); //System.out.println("right"); } else if (y == layer) {//top d tArea += width * 4 - 1 - (x - (layer - 1) * 2 + layer); //System.out.println("top"); } else if (y == size - layer + 1) {//bottom d tArea += width * 2 - 1 - (width - (x - (layer - 1))); //System.out.println("bottom"); } //current layer = lower of x or y //layer width = (size-(layer-1)*2) //layer area = (size-(layer-1)*2)*4-4 //go through earlier spirals to get total //then remove extra that hasnt been reached yet cout << to_string(tArea) << "\n"; } } // Run program: Ctrl + F5 or Debug > Start Without Debugging menu // Debug program: F5 or Debug > Start Debugging menu // Tips for Getting Started: // 1. Use the Solution Explorer window to add/manage files // 2. Use the Team Explorer window to connect to source control // 3. Use the Output window to see build output and other messages // 4. Use the Error List window to view errors // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
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: TIME LIMIT EXCEEDED
input |
---|
1000000000 1000 177757853 827347032 409613589 419171337 739269360 256524697 328695530 896842209 ... |
correct output |
---|
571375684522141210 967321186816598569 762879105851175000 370065046779516790 936897883750373771 ... |
user output |
---|
(empty) |