CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Lentsu
Submission time:2020-10-06 22:30:21 +0300
Language:C++11
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s1, 2, 3details
#30.01 s1, 2, 3details
#40.01 s1, 2, 3details
#50.01 s1, 2, 3details
#60.01 s1, 2, 3details
#70.01 s1, 2, 3details
#80.01 s2, 3details
#90.01 s2, 3details
#100.01 s2, 3details
#110.02 s3details
#120.03 s3details
#130.03 s3details

Code

#include <iostream>

int main() {
	
	int n;
	std::cin >> n;

	int board[n][n];

	//initialize board
	for(int y = 0; y != n; ++y)
		for (int x = 0; x != n; ++x)
			board[x][y] = 0;

	//The initialization kinda makes things harder so let's set the first depth manually
	board[1][2] = board[2][1] = 1;

	int depth = 2;
	int insertion_counter = 2;
	int temp;

	while (true) {
		
		std::cout << "Current depth: " << depth << std::endl;

		//save number of insertions
		temp = insertion_counter;

		for (int y = 0; y != n; ++y)
			for (int x = 0; x != n; ++x) {

				// If starting point
				if(board[x][y] == depth-1) {

					//Possible moves:
					//	(x+2, y+1)
					//	(x+2, y-1)
					//	(x-2, y+1)
					//	(x-2, y-1)
					//
					//	(x+1, y+2)
					//	(x+1, y-2)
					//	(x-1, y+2)
					//	(x-1, y-2)
					
					//	check if one or more moves are possible
					
					// Moves x+2
					if (x+2 < n) {
						
						// Move (+2, +1)
						if (y+1 < n) {
							if (board[x+2][y+1] == 0) {
								
								std::cout << "move: (" << x << ", " << y << ") -> (" << x+2 << ", " << y+1 << ")" << std::endl;

								board[x+2][y+1] = depth;
								++insertion_counter;
							}
						}
						
						// Move (+2, -1)
						if (y-1 >= 0) {
							if (board[x+2][y-1] == 0) {

								std::cout << "move: (" << x << ", " << y << ") -> (" << x+2 << ", " << y-1 << ")" << std::endl;

								board[x+2][y-1] = depth;
								++insertion_counter;
							}
						}
					}

					// Moves x-2
					if (x-2 >= 0) {
						
						// Move (-2, +1)
						if (y+1 < n) {
							if (board[x-2][y+1] == 0) {

								std::cout << "move: (" << x << ", " << y << ") -> (" << x-2 << ", " << y+1 << ")" << std::endl;

								board[x-2][y+1] = depth;
								++insertion_counter;
							}
						}
						
						// Move (-2, -1)
						if (y-1 >= 0) {
							if (board[x-2][y-1] == 0) {

								std::cout << "move: (" << x << ", " << y << ") -> (" << x-2 << ", " << y-1 << ")" << std::endl;

								board[x-2][y-1] = depth;
								++insertion_counter;
							}
						}
					}

					// Moves y+2
					if (y+2 < n) {

						// Move (+1, +2)
						if (x+1 < n) {
							if (board[x+1][y+2] == 0) {

								std::cout << "move: (" << x << ", " << y << ") -> (" << x+1 << ", " << y+2 << ")" << std::endl;

								board[x+1][y+2] = depth;
								++insertion_counter;
							}
						}

						// Move (-1, +2)
						if (x-1 >= 0) {
							if (board[x-1][y+2] == 0) {

								std::cout << "move: (" << x << ", " << y << ") -> (" << x-1 << ", " << y+2 << ")" << std::endl;

								board[x-1][y+2] = depth;
								++insertion_counter;
							}
						}
					}

					// Moves y-2
					if (y-2 >= 0) {

						// Move (+1, -2)
						if (x+1 < n) {
							if (board[x+1][y-2] == 0){

								std::cout << "move: (" << x << ", " << y << ") -> (" << x+1 << ", " << y-2 << ")" << std::endl;

								board[x+1][y-2] = depth;
								++insertion_counter;
							}
						}

						// Move (-1, -2)
						if (x-1 >= 0) {
							if (board[x-1][y-2] == 0) {

								std::cout << "move: (" << x << ", " << y << ") -> (" << x-1 << ", " << y-2 << ")" << std::endl;

								board[x-1][y-2] = depth;
								++insertion_counter;
							}
						}
					}

				}
			// End of for
			}

		//If an insertion wasn't made, break the loop
		if (temp == insertion_counter)
			break;
		
		//increment depth by 1
		++depth;
	}

	//Initial point at (0, 0)
	board[0][0] = 0;

	//Print the result
	for (int y = 0; y != n; ++y) {
		for (int x = 0; x != n; ++x)
			std::cout << board[x][y] << " ";
		std::cout << std::endl;
	}
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
4

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

user output
Current depth: 2
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
move: (2, 1) -> (3, 3)
move: (2, 1) -> (1, 3)
...

Test 2

Group: 1, 2, 3

Verdict:

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
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 3

Group: 1, 2, 3

Verdict:

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
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 4

Group: 1, 2, 3

Verdict:

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
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 5

Group: 1, 2, 3

Verdict:

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
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 6

Group: 1, 2, 3

Verdict:

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
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 7

Group: 1, 2, 3

Verdict:

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
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 8

Group: 2, 3

Verdict:

input
25

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

user output
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 9

Group: 2, 3

Verdict:

input
49

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

user output
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 10

Group: 2, 3

Verdict:

input
50

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

user output
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 11

Group: 3

Verdict:

input
75

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

user output
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 12

Group: 3

Verdict:

input
99

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

user output
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...

Test 13

Group: 3

Verdict:

input
100

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

user output
Current depth: 2
move: (2, 1) -> (4, 2)
move: (2, 1) -> (4, 0)
move: (2, 1) -> (0, 2)
move: (2, 1) -> (0, 0)
...