CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:pvartiovaara
Submission time:2020-09-29 16:22:00 +0300
Language:C++11
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED27
#2ACCEPTED31
#3ACCEPTED42
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#6ACCEPTED0.01 s1, 2, 3details
#7ACCEPTED0.01 s1, 2, 3details
#8ACCEPTED0.01 s2, 3details
#9ACCEPTED0.01 s2, 3details
#10ACCEPTED0.01 s2, 3details
#11ACCEPTED0.01 s3details
#12ACCEPTED0.01 s3details
#13ACCEPTED0.01 s3details

Code

#include <bits/stdc++.h>
#include <cstring>
#include <queue>

#define DEBUG
#define MP(x, y) std::make_pair(x, y)

int n;

inline bool outOfBounds(int a, int b) {
	if (a < 0 || b < 0) { return true; }
	if (a > n-1 || b > n-1) { return true; }
	return false;
}

int main() {
	std::cin>> n;
	//n = 50;
	int res[n][n]; /* this is [y][x] */
	memset(res, -1, sizeof(res[0][0])*n*n);
	// now we have the board initialized

	std::queue<std::pair<std::pair<int,int>,int> > comp; /* queue for the nodes to be computed ((x, y), iter) */
	comp.push(MP(MP(0,0), 0)); /* push starting point */

	int c = 0;
	std::pair<int,int> coord;
	while (!comp.empty()) {
		//std::cout<< "stack size: " << comp.size() << std::endl;
		coord = comp.front().first;
		c = comp.front().second;
		comp.pop();
		//std::cerr<< "current coords: " << coord.first << ' ' << coord.second << std::endl;
		//std::cerr<< "value at current coords: " << res[coord.first][coord.second] << std::endl;
		//if (res[coord.second][coord.first] != -1) {
		if (res[coord.second][coord.first] > -1) { continue; } /* already visited */
		//}
		res[coord.second][coord.first] = c;
		res[coord.first][coord.second] = c;
		c++;
		if(!outOfBounds(coord.first+1, coord.second-2)) { comp.push(MP(MP(coord.first+1, coord.second-2), c)); } /* top right */
		if(!outOfBounds(coord.first-1, coord.second-2)) { comp.push(MP(MP(coord.first-1, coord.second-2), c)); } /* top left */
		if(!outOfBounds(coord.first+2, coord.second+1)) { comp.push(MP(MP(coord.first+2, coord.second+1), c)); } /* right bottom */
		if(!outOfBounds(coord.first+2, coord.second-1)) { comp.push(MP(MP(coord.first+2, coord.second-1), c)); } /* right top */
		if(!outOfBounds(coord.first+1, coord.second+2)) { comp.push(MP(MP(coord.first+1, coord.second+2), c)); } /* bottom right */
		if(!outOfBounds(coord.first-1, coord.second+2)) { comp.push(MP(MP(coord.first-1, coord.second+2), c)); } /* bottom left */
		if(!outOfBounds(coord.first-2, coord.second-1)) { comp.push(MP(MP(coord.first-2, coord.second-1), c)); } /* left up */
		if(!outOfBounds(coord.first-2, coord.second+1)) { comp.push(MP(MP(coord.first-2, coord.second+1), c)); } /* left down */
		//std::cout<< "stack size: " << comp.size() << std::endl;
	}
	for (int y = 0; y < n; y++) {
		for (int x = 0; x < n; x++) {
			std::cout<< res[y][x] << ' ';
		}
		std::cout<< std::endl;
	}
	return 0;
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
4

correct output
0 3 2 5 
3 4 1 2 
2 1 4 3 
5 2 3 2 

user output
0 3 2 5 
3 4 1 2 
2 1 4 3 
5 2 3 2 

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
5

correct output
0 3 2 3 2 
3 4 1 2 3 
2 1 4 3 2 
3 2 3 2 3 
2 3 2 3 4 

user output
0 3 2 3 2 
3 4 1 2 3 
2 1 4 3 2 
3 2 3 2 3 
2 3 2 3 4 

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
6

correct output
0 3 2 3 2 3 
3 4 1 2 3 4 
2 1 4 3 2 3 
3 2 3 2 3 4 
2 3 2 3 4 3 
...

user output
0 3 2 3 2 3 
3 4 1 2 3 4 
2 1 4 3 2 3 
3 2 3 2 3 4 
2 3 2 3 4 3 
...

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
7

correct output
0 3 2 3 2 3 4 
3 4 1 2 3 4 3 
2 1 4 3 2 3 4 
3 2 3 2 3 4 3 
2 3 2 3 4 3 4 
...

user output
0 3 2 3 2 3 4 
3 4 1 2 3 4 3 
2 1 4 3 2 3 4 
3 2 3 2 3 4 3 
2 3 2 3 4 3 4 
...

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
8

correct output
0 3 2 3 2 3 4 5 
3 4 1 2 3 4 3 4 
2 1 4 3 2 3 4 5 
3 2 3 2 3 4 3 4 
2 3 2 3 4 3 4 5 
...

user output
0 3 2 3 2 3 4 5 
3 4 1 2 3 4 3 4 
2 1 4 3 2 3 4 5 
3 2 3 2 3 4 3 4 
2 3 2 3 4 3 4 5 
...

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
9

correct output
0 3 2 3 2 3 4 5 4 
3 4 1 2 3 4 3 4 5 
2 1 4 3 2 3 4 5 4 
3 2 3 2 3 4 3 4 5 
2 3 2 3 4 3 4 5 4 
...

user output
0 3 2 3 2 3 4 5 4 
3 4 1 2 3 4 3 4 5 
2 1 4 3 2 3 4 5 4 
3 2 3 2 3 4 3 4 5 
2 3 2 3 4 3 4 5 4 
...

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
10

correct output
0 3 2 3 2 3 4 5 4 5 
3 4 1 2 3 4 3 4 5 6 
2 1 4 3 2 3 4 5 4 5 
3 2 3 2 3 4 3 4 5 6 
2 3 2 3 4 3 4 5 4 5 
...

user output
0 3 2 3 2 3 4 5 4 5 
3 4 1 2 3 4 3 4 5 6 
2 1 4 3 2 3 4 5 4 5 
3 2 3 2 3 4 3 4 5 6 
2 3 2 3 4 3 4 5 4 5 
...

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
25

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
49

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
50

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 11

Group: 3

Verdict: ACCEPTED

input
75

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 12

Group: 3

Verdict: ACCEPTED

input
99

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 13

Group: 3

Verdict: ACCEPTED

input
100

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...