QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#180973 | #7227. The Magic Square | ucup-team288# | WA | 1ms | 3440kb | C++20 | 1.1kb | 2023-09-16 14:50:47 | 2023-09-16 14:50:47 |
Judging History
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