Submission #391563

# Submission time Handle Problem Language Result Execution time Memory
391563 2021-04-19T11:14:16 Z soba Prosjecni (COCI16_prosjecni) C++14
120 / 120
2 ms 332 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll t , n , k,x , njr  , need;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    if(n==2)
    {
        cout << -1;
        return 0;
    }
    if(n%2==1)
    {
        for(int i = 0; i < n ; i++)
        {
            for(int j = 1 ; j <=n ;j++)
            {
                cout << i*n + j << " ";
            }
            cout << "\n";
        }
        return 0;
    }
    int arr[n+1][n+1];
    int sum=0;
    for(int i = 1 ; i  < n ; i++)
    {
        arr[1][i]=i;
        sum+=i;
    }
    arr[1][n]=(n*arr[1][n-1])-sum;
    arr[2][1]=arr[1][n]+1;
    sum=arr[1][1]+arr[2][1];
    for(int i = 3 ; i<n ; i++ )
    {
        arr[i][1]=arr[i-1][1]+(arr[2][1]-arr[1][1]);
        sum+=arr[i][1];
    }
    arr[n][1]=(n*arr[n-1][1])-sum;
    for(int i = 2; i <= n ; i++)
    {
        for(int j = 2 ; j<= n ; j++)
        {
            arr[i][j]=arr[i-1][j]+(arr[i][j-1]-arr[i-1][j-1]);
        }
    }
    for(int i = 1; i <= n ; i++)
    {
        for(int j = 1 ; j<= n ; j++)
        {
            cout << arr[i][j]<< " " ;
        }
        cout << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct