CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:2
Submission time:2019-09-30 18:08:16 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#30.01 sdetails
#40.01 sdetails
#50.01 sdetails
#60.01 sdetails

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>

inline int& get(int* vals, int n, int x, int y)
{
	return vals[x + y * n];
}
inline void set(int* vals, int n, int x, int y, int val)
{
	vals[x + y * n] = val;
}

void fill_to(std::vector<int>& v, int n)
{
	v.resize(n);
	for (int i = 0; i < n; i++)
		v[i] = i + 1;
}

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

	int* matrix = new int[n * n];
	// i = y
	// k = x
	for (int i = 0; i < n; i++)
	{
		for (int k = 0; k < n; k++)
		{
			// Find available
			std::vector<int> available;
			fill_to(available, n);

			for (int j = 0; j < i; j++)
			{
				available[get(matrix, n, k, j) - 1] = -1;
			}
			
			for (int j = 0; j < k; j++)
			{
				available[get(matrix, n, j, i) - 1] = -1;
			}
			std::remove_if(std::begin(available), std::end(available), [](int v) {return v == -1; });
			
			set(matrix, n, k, i, available[0]);
		}
	}

	for (int i = 0; i < n * n; i++)
	{
		int x = i % 4;
		std::cout << matrix[i];
		if (x == 3) std::cout << "\n";
		if (x < 3) std::cout << " ";
	}

	return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output

user output

Test 2

Verdict: ACCEPTED

input
2

correct output
1 2 
2 1 

user output
1 2 2 1

Test 3

Verdict:

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
(empty)

Error:
munmap_chunk(): invalid pointer

Test 4

Verdict:

input
42

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

user output
(empty)

Error:
munmap_chunk(): invalid pointer

Test 5

Verdict:

input
99

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

user output
(empty)

Error:
munmap_chunk(): invalid pointer

Test 6

Verdict:

input
100

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

user output
(empty)

Error:
munmap_chunk(): invalid pointer