#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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |