# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1256209 | nanaseyuzuki | Prosjecni (COCI16_prosjecni) | C++20 | 2 ms | 840 KiB |
#include <bits/stdc++.h>
/*
--> Author: Kazuki_Hoshino__8703 <--
I love Nanasaki Ai ☆*: .。. o(≧▽≦)o .。.:*☆
*/
#define fi first
#define se second
#define pii pair<int, int>
#define ll long long
using namespace std;
const int mn = 1e3 + 5, bm = (1 << 15) + 1, mod = 1e9 + 7;
const ll inf = 1e9 + 7, base = 311;
int n, a[mn][mn];
void solve(){
cin >> n;
if(n == 2){
cout << -1 << '\n';
return;
}
for(int i = 1; i <= n - 1; i++){
a[1][i] = i;
}
a[1][n] = n * (n - 1) / 2;
for(int i = 2; i < n; i++){
for(int j = 1; j <= n; j++){
a[i][j] = a[i - 1][j] + n * (n - 1) / 2;
}
}
for(int j = 1; j <= n; j++){
int total = 0;
for(int i = 1; i < n; i++) total += a[i][j];
a[n][j] = n * a[n - 1][j] - total;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cout << a[i][j] << ' ';
}
cout << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if(fopen("ROBOT.INP", "r")){
freopen("ROBOT.INP", "r", stdin);
freopen("ROBOT.OUT", "w", stdout);
}
int t = 1;
// cin >> t;
while(t --){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |