Submission #226194

# Submission time Handle Problem Language Result Execution time Memory
226194 2020-04-22T19:43:40 Z osaaateiasavtnl Prosjecni (COCI16_prosjecni) C++14
120 / 120
5 ms 512 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 107;
int a[N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
 
    if (n == 2) {
        cout << "-1" << endl;
        exit(0);
    }   

    int sh = n * (n - 1) / 2;
    for (int i = 0; i < n; ++i) {
        int sum = 0, r = 0;
        for (int j = 0; j < n - 1; ++j) {
            a[i][j] = i * sh + j;
            sum += a[i][j];
            r = a[i][j];
        }   
        a[i][n - 1] = r * n - sum;
    }   
    for (int j = 0; j < n; ++j) {
        int sum = 0, r = 0;
        for (int i = 0; i < n - 1; ++i) {
            sum += a[i][j];
            r = a[i][j];
        }   
        a[n - 1][j] = r * n - sum;
    }   

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << a[i][j] << ' ';
        }   
        cout << endl;
    }   
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct