#include <bits/stdc++.h>
#define fio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
using namespace std ;
signed main ()
{
fio ;
int n , sum = 1 ;
cin >> n ;
if ( n == 2 ) cout << -1 ;
else if ( n % 2 )
{
for ( int i = 0 ; i < n ; i++ )
{
for ( int k = 0 ; k < n ; k++ )
{
cout << sum << " " ;
sum++ ;
}
cout << "\n" ;
}
return 0 ;
}
else
{
int a[n][n] , sum = 1 ;
for ( int i = 0 ; i < n-1 ; i++ )
{
for ( int k = 0 ; k < n-1 ; k++ )
{
if ( k != n-1 )
{
a[i][k] = sum ;
sum++ ;
}
}
}
for ( int i = 0 ; i < n ; i++ )
{
int pref = 0 ;
for ( int k = 0 ; k < n-1 ; k++ ) pref += a[i][k] ;
a[i][n-1] = pref ;
}
for ( int k = 0 ; k < n ; k++ )
{
int pref = 0 , av = a[n-2][k] ;
for ( int i = 0 ; i < n-1 ; i++ ) pref += av - a[i][k] ;
a[n-1][k] = pref + a[n-2][k] ;
}
for ( int i = 0 ; i < n ; i++ )
{
for ( int k = 0 ; k < n ; k++ ) cout << a[i][k] << " " ;
cout << "\n" ;
}
}
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Not distinct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Not distinct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Incorrect |
0 ms |
204 KB |
Not distinct |
6 |
Incorrect |
0 ms |
204 KB |
Not distinct |
7 |
Incorrect |
1 ms |
332 KB |
Not distinct |
8 |
Incorrect |
1 ms |
332 KB |
Not distinct |
9 |
Incorrect |
1 ms |
332 KB |
Not distinct |
10 |
Incorrect |
1 ms |
332 KB |
Not distinct |