CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:antti_p
Submission time:2019-10-08 10:15:30 +0300
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'void ruudukko()':
input/code.cpp:27:50: warning: 'min' may be used uninitialized in this function [-Wmaybe-uninitialized]
    std::cout << min << (c == input - 1 ? "" : " ");
                                                  ^

Code

#include <iostream>

void ruudukko() {
	int input;
	std::cin >> input;
	int* matrix = new int[input*input];
	bool* included = new bool[2*input];
	for (int r = 0; r < input; ++r) {
		for (int c = 0; c < input; ++c) {
			for (int i = 0; i < 2*input; ++i) {
				included[i] = false;
			}
			for (int top = 0; top < r; ++top) {
				included[matrix[top*input + c] - 1] = true;
			}
			for (int left = 0; left < c; ++left) {
				included[matrix[r*input + left] - 1] = true;
			}
			int min;
			for (int i = 0; i < 2*input; ++i) {
				if (!included[i]) {
					min = i + 1;
					break;
				}
			}
			matrix[r*input + c] = min;
			std::cout << min << (c == input - 1 ? "" : " ");
		}
		std::cout << "\n";
	}
	delete[] matrix;
	delete[] included;
}

int main() {
	ruudukko();
	return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output

user output
1

Test 2

Verdict: ACCEPTED

input
2

correct output
1 2 
2 1 

user output
1 2
2 1

Test 3

Verdict: ACCEPTED

input
5

correct output
1 2 3 4 5 
2 1 4 3 6 
3 4 1 2 7 
4 3 2 1 8 
5 6 7 8 1 

user output
1 2 3 4 5
2 1 4 3 6
3 4 1 2 7
4 3 2 1 8
5 6 7 8 1

Test 4

Verdict: ACCEPTED

input
42

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
Truncated

Test 5

Verdict: ACCEPTED

input
99

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
Truncated

Test 6

Verdict: ACCEPTED

input
100

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
Truncated