답안 #631569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631569 2022-08-18T08:44:18 Z dozer Prosjecni (COCI16_prosjecni) C++14
36 / 120
1 ms 468 KB
#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 - 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 - 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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Average condition doesn't hold.
4 Correct 0 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Average condition doesn't hold.
6 Incorrect 1 ms 340 KB Average condition doesn't hold.
7 Incorrect 1 ms 340 KB Average condition doesn't hold.
8 Incorrect 1 ms 340 KB Average condition doesn't hold.
9 Incorrect 1 ms 468 KB Average condition doesn't hold.
10 Incorrect 1 ms 468 KB Average condition doesn't hold.