Cod sursa(job #3292294)

Utilizator BOSSSTEFANPetrescu Ioan Stefan BOSSSTEFAN Data 7 aprilie 2025 20:07:44
Problema Oras Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <bits/stdc++.h>
#define inf 1e9
using namespace std;
const int nmax = 200;
bool mat[nmax + 1][nmax + 1];
void afisare(int n)
{
    int i, j;
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
            cout << mat[i][j];
        cout << '\n';
    }
}
int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(0);
    freopen("oras.in", "r", stdin);
    freopen("oras.out", "w", stdout);
    int n, i, j;
    cin >> n;
    if(n == 4)
        cout << -1;
    else
    {
        mat[1][2] = 1;
        mat[2][3] = 1;
        mat[3][1] = 1;
        if(n == 3)
            afisare(n);
        else
        {
            i = 3;
            while(i + 2 <= n)
            {
                for(j = 1; j <= i; j++)
                {
                    mat[j][i + 1] = 1;
                    mat[i + 2][j] = 1;
                }
                mat[i + 1][i + 2] = 1;
                i += 2;
            }
            if(n % 2 == 0)
            {
                mat[n - 3][n] = 1;
                mat[n][n - 4] = 1;
                mat[n - 2][n] = 1;
                mat[n][n - 1] = 1;
                for(i = n - 5; i >= 1; i--)
                    mat[i][n] = 1;
            }
            afisare(n);
        }
    }
    return 0;
}