QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266876#7740. Puzzle: Question Marktime_interspace#WA 0ms3972kbC++204.0kb2023-11-26 18:45:182023-11-26 18:45:20

Judging History

你现在查看的是最新测评结果

  • [2023-11-26 18:45:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3972kb
  • [2023-11-26 18:45:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2005;
int T, n, ans[N][N];
int num;
void solve4(int n)
{
	printf("%d\n", n * n / 4);
	//num = 0;
	for (int i = 1; i <= n; i += 4)
		for (int j = 1; j <= n; j += 2)
		{
			num++;
			ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = num;
			num++;
			ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = num;
		}
}
void solve2(int n)
{
	printf("%d\n", n * n / 4 - 1);
	//num = 0;
	for (int i = 1; i <= n - 2; i += 4)
		for (int j = 1; j <= n; j += 2)
		{
			num++;
			ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = num;
			num++;
			ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = num;
		}
	int i = n - 1;
	for (int j = 1; j <= n - 2; j += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 2] = num;
		num++;
		ans[i + 1][j + 1] = ans[i][j + 2] = ans[i][j + 3] = ans[i + 1][j + 3] = num;
	}
}
void solve13(int n, int m, int x, int y)
{
	num++;
	ans[x][y] = ans[x + 1][y + 1] = ans[x][y + 2] = ans[x + 1][y + 2] = num;
	num++;
	ans[x][y + 1] = ans[x + 1][y] = ans[x + 2][y] = ans[x + 2][y + 1] = num;
	if (n == 3)
	{
		num++;
		y += 3;
		ans[x][y + 1] = ans[x + 1][y] = ans[x + 2][y] = ans[x + 2][y + 1] = num;
		return;
	}
	int i = x;
	for (int j = y + 3; j <= y + m - 1; j += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 2] = num;
		num++;
		ans[i + 1][j + 1] = ans[i][j + 2] = ans[i][j + 3] = ans[i + 1][j + 3] = num;
	}
	i = x + n - 2;
	for (int j = y + 3; j <= y + m - 1; j += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 2] = num;
		num++;
		ans[i + 1][j + 1] = ans[i][j + 2] = ans[i][j + 3] = ans[i + 1][j + 3] = num;
	}
	int j = y;
	for (int i = x + 3; i <= x + n - 1; i += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = num;
		num++;
		ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = num;
	}
	j = y + m - 2;
	for (int i = x + 3; i <= x + n - 1; i += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = num;
		num++;
		ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = num;
	}
	num++;
	x = x + n - 1;
	y = y + m - 1;
	ans[x][y] = ans[x - 1][y - 1] = ans[x][y - 2] = ans[x - 1][y - 2] = num;
	num++;
	ans[x][y - 1] = ans[x - 1][y] = ans[x - 2][y] = ans[x - 2][y - 1] = num;
	solve13(n - 2, m - 2, x + 2, y + 2);
}
void solve1(int n)
{
	if (n == 1)
	{
		puts("0");
		return;
		}
	printf("%d\n", n * n / 4 - 1);
	//num = 0;
	int i = 1;
	for (int j = 1; j <= n - 1; j += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 2] = num;
		num++;
		ans[i + 1][j + 1] = ans[i][j + 2] = ans[i][j + 3] = ans[i + 1][j + 3] = num;
	}
	num++;
	solve13(n - 2, n, 3, 1);
}
void solve3(int n)
{
	printf("%d\n", n * n / 4 - 1);
	//num = 0;
	int i = n - 1;
	for (int j = 1; j <= n - 3; j += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 2] = num;
		num++;
		ans[i + 1][j + 1] = ans[i][j + 2] = ans[i][j + 3] = ans[i + 1][j + 3] = num;
	}
	int j = n - 1;
	for (int i = 1; i <= n - 3; i += 4)
	{
		num++;
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = num;
		num++;
		ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = num;
	}
	num++;
	ans[n - 2][n - 1] = ans[n - 2][n] = ans[n - 1][n - 1] = ans[n][n] = num;
	num++;
	ans[n - 1][n - 2] = ans[n][n - 2] = ans[n][n - 1] = ans[n - 1][n] = num;
	solve1(n - 2);
}
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++) ans[i][j] = 0;
		num = 0;
		if (n % 4 == 0) solve4(n);
		if (n % 4 == 2) solve2(n);
		if (n % 4 == 1) solve1(n);
		if (n % 4 == 3) solve3(n);
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
			{
				printf("%d", ans[i][j]);
				if (j < n) putchar(' ');
			}
			puts("");
		}
		//puts("");
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3972kb

input:

2
3
4

output:

1
0
0 1 1
2 1 2
2 2 1
4
1 1 3 3
1 2 3 4
2 1 4 3
2 2 4 4

result:

wrong answer Integer parameter [name=a_ij] equals to 2, violates the range [0, 1] (test case 1)