Cod sursa(job #1464401)

Utilizator cristian.caldareaCaldarea Cristian Daniel cristian.caldarea Data 23 iulie 2015 13:38:53
Problema Oras Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
#include <cstdlib>
#include <vector>
using namespace std;

ifstream fin ("oras.in");
ofstream fout ("oras.out");

const int Dim = 203;

int G[Dim][Dim];
int n;

void Solve(int x);

int main()
{
    fin >> n;
    if (n < 3 || n == 4)
    {
        fout << -1;
        return 0;
    }
    Solve(n);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
            fout << G[i][j];
        fout << '\n';
    }
    fin.close();
    fout.close();
}

void Solve(int x)
{

    if (x == 3)
    {
        G[1][2] = G[2][3] = G[3][1] = 1;
        return;
    }
    if (x == 6)
    {
        G[1][2] = G[1][4] = G[1][6] = 1;
        G[2][3] = G[2][5] = G[2][6] = 1;
        G[3][1] = G[3][5] = 1;
        G[4][2] = G[4][3] = G[4][5] = 1;
        G[5][1] = G[5][6] = 1;
        G[6][4] = G[6][3] = 1;
        return;
    }
    Solve(x-2);
    for (int i = 1; i < x-1; ++i)
        G[i][x] = 1, G[x-1][i] = 1;
    G[x][x-1] = 1;
}