Submission #631570

#TimeUsernameProblemLanguageResultExecution timeMemory
631570dozerProsjecni (COCI16_prosjecni)C++14
120 / 120
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define pb push_back #define pii pair<int, int> #define st first #define nd second #define sp " " #define endl "\n" #define N 105 #define modulo 1000000007 #define int long long int arr[N][N]; int32_t main() { fastio(); int n; cin>>n; if (n == 1) { cout<<1<<endl; return 0; } if (n == 2) { cout<<-1<<endl; return 0; } if (n % 2 == 0) { int sum = 0; for (int i = 1; i < n; i++) { arr[i][1] = arr[i - 1][n] + 1; sum += arr[i][1]; for (int j = 2; j < n; j++) arr[i][j] = arr[i][j - 1] + 1; arr[i][n] = arr[i][n - 1] + (n / 2) + 1; } int w = arr[n / 2 + 1][1] * n; arr[n][1] = w - sum; for (int j = 2; j < n; j++) arr[n][j] = arr[n][j - 1] + 1; arr[n][n] = arr[n][n - 1] + (n / 2) + 1; } else { int cntr = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) arr[i][j] = cntr++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout<<arr[i][j]<<sp; cout<<endl; } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...