| Task: | Ruudukko |
| Sender: | aki |
| Submission time: | 2019-10-01 13:53:47 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 100 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
| #2 | ACCEPTED | 0.01 s | details |
| #3 | ACCEPTED | 0.01 s | details |
| #4 | ACCEPTED | 0.01 s | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | ACCEPTED | 0.04 s | details |
Code
#include <iostream>
#include <algorithm>
void set(int* m, int n, int x, int y, int v)
{
m[x + y * n] = v;
}
int get(int* m, int n, int x, int y)
{
return m[x + n * y];
}
bool is_left_or_above(int* m, int n, int x, int y, int v)
{
for(int y_i = 0; y_i < y; y_i++)
{
if(get(m, n, x, y_i) == v)
return true;
}
for(int x_i = 0; x_i < x; x_i++)
{
if(get(m, n, x_i, y) == v)
return true;
}
return false;
}
int main()
{
int n;
std::cin >> n;
int* matrix = new int[n * n];
for(int i = 0; i < n * n; i++)
{
matrix[i] = 0;
}
for(int y = 0; y < n; y++)
{
for(int x = 0; x < n; x++)
{
int val = 1;
while(is_left_or_above(matrix, n, x, y, val))
{
val++;
}
set(matrix, n, x, y, val);
std::cout << val;
if(x < n)
std::cout << " ";
}
if(y < n)
std::cout << "\n";
}
return 0;
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 1 |
| correct output |
|---|
| 1 |
| 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 |
