QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#180973#7227. The Magic Squareucup-team288#WA 1ms3440kbC++201.1kb2023-09-16 14:50:472023-09-16 14:50:47

Judging History

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

  • [2023-09-16 14:50:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3440kb
  • [2023-09-16 14:50:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
const int MAX_N = 2000;

int res[MAX_N][MAX_N];

pair<int,int> get_ab(int v) {
	return {v/2, v/2-1};
}
void cons(int x, int y) {
}
int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	cin >> n;
	if (set<int>{2, 3, 5}.count(n))
		return cout << "Impossible\n", 0;
	cout << "Possible\n";

	bool cp = false;
	if (n % 2) {
		n -= 3;
		cp = true;
	}

	auto [a, b] = get_ab(n);
	assert(a * a - b * b == (n-1));

	int uv = 1;
	for (int i = 0;i < b;++i)
		for (int j = 0;j < b;++j)
			res[i][j] = uv;
	++uv;

	for (int i = 0;i < a;++i) for (int j =0 ;j < a;++j)
		if (res[i][j] == 0) res[i][j] = uv++;

	if (cp) {
		for (int i = 0;i < a;++i)
			for (int j = 0;j < a;++j)
				res[i][j+a] = uv;
		++uv;
		for (int i = 0;i < a;++i)
			for (int j = 0;j < a;++j)
				res[i+a][j] = uv;
		++uv;
		for (int i = 0;i < a;++i)
			for (int j = 0;j < a;++j)
				res[i+a][j+a] = uv;
		++uv;
		a *= 2;
	}

	cout << a << '\n';
	for (int i = 0;i < a;++i) for (int j = 0;j < a;++j)
		cout << res[i][j] << " \n"[j+1==a];

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3440kb

input:

2

output:

Impossible

result:

ok No solution for 2 squares

Test #2:

score: 0
Accepted
time: 0ms
memory: 3436kb

input:

4

output:

Possible
2
1 2
3 4

result:

ok answer 4 squares of 1 different sizes in total 2 * 2

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3436kb

input:

1

output:

Possible
-2

result:

wrong answer Illegal construction