CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:aki
Submission time:2019-10-01 13:53:47 +0300
Language: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.04 sdetails
#6ACCEPTED0.04 sdetails

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

user output

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 ...

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 ...

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 ...