CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:Epe
Submission time:2019-10-08 20:20:40 +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.03 sdetails
#6ACCEPTED0.03 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

int main(){
    int size;
    cin >> size;

    short grid[size][size] = {0};
    vector<set<short>> rivit(size-1);
    vector<set<short>> sarakkeet(size-1);

    for(int i = 0; i < size; i++){
        grid[i][0] = i+1;
        grid[0][i] = i+1;
        if(i > 0) {
            set<short> temp;
            temp.insert(i + 1);
            temp.insert(1);
            rivit[i-1] = temp;
            sarakkeet[i-1] = temp;
        }
    }

    for(int i = 1; i < size; i++){
        grid[i][i] = 1;
        for(int p = i+1; p < size; p++){
            int x1 = i;
            int y1 = p;

            int x2 = p;
            int y2 = i;


            for(int n = 1; n <= size*2; n++){
                if(sarakkeet[x1-1].find(n) == sarakkeet[x1-1].end() && rivit[y1-1].find(n) == rivit[y1-1].end()){
                    grid[y1][x1] = n;
                    sarakkeet[x1-1].insert(n);
                    rivit[y1-1].insert(n);
                    break;
                }
            }
            for(int n = 1; n <= size*2; n++){
                if(sarakkeet[x2-1].find(n) == sarakkeet[x2-1].end() && rivit[y2-1].find(n) == rivit[y2-1].end()){
                    grid[y2][x2] = n;
                    sarakkeet[x2-1].insert(n);
                    rivit[y2-1].insert(n);
                    break;
                }
            }
        }
    }



    for(int y = 0; y < size; y++){
        for(int x = 0; x < size; x++){
            cout << grid[y][x] << " ";
        }
        cout << endl;
    }
}

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