QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176255 | #7227. The Magic Square | ucup-team004# | WA | 0ms | 3864kb | C++20 | 1.5kb | 2023-09-11 13:40:27 | 2023-09-11 13:40:29 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
int m;
for (int i = 1; ; i++) {
if ((i * i >= n && (i * i - n) % 3 == 0) || (i * i - 8 >= n && (i * i - 8 - n) % 3 == 0)) {
m = i;
break;
}
}
std::vector a(m, std::vector<int>(m));
int tot = m * m;
int cur = 0;
if ((tot - n) % 3 != 0) {
cur++;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
a[i][j] = cur;
}
}
tot -= 8;
}
for (int i = 0; i + 1 < m; i++) {
for (int j = 0; j + 1 < m; j++) {
if (a[i][j] == 0 && tot > n) {
tot -= 3;
cur++;
a[i][j] = cur;
a[i][j + 1] = cur;
a[i + 1][j] = cur;
a[i + 1][j + 1] = cur;
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == 0) {
a[i][j] = ++cur;
}
}
}
if (tot != n) {
std::cout << "Impossible\n";
return 0;
}
std::cout << "Possible\n";
std::cout << m << "\n";
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
std::cout << a[i][j] << " \n"[j == m - 1];
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
2
output:
Impossible
result:
ok No solution for 2 squares
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
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: 0
Accepted
time: 0ms
memory: 3660kb
input:
1
output:
Possible 1 1
result:
ok answer 1 squares of 1 different sizes in total 1 * 1
Test #4:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
3
output:
Impossible
result:
ok No solution for 3 squares
Test #5:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
5
output:
Impossible
result:
ok No solution for 5 squares
Test #6:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
6
output:
Possible 3 1 1 2 1 1 3 4 5 6
result:
ok answer 6 squares of 2 different sizes in total 3 * 3
Test #7:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
7
output:
Possible 4 1 1 2 2 1 1 2 2 3 3 4 5 3 3 6 7
result:
ok answer 7 squares of 2 different sizes in total 4 * 4
Test #8:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
8
output:
Possible 4 1 1 1 2 1 1 1 3 1 1 1 4 5 6 7 8
result:
ok answer 8 squares of 2 different sizes in total 4 * 4
Test #9:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
9
output:
Possible 3 1 2 3 4 5 6 7 8 9
result:
ok answer 9 squares of 1 different sizes in total 3 * 3
Test #10:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
10
output:
Possible 4 1 1 2 2 1 1 2 2 3 4 5 6 7 8 9 10
result:
ok answer 10 squares of 2 different sizes in total 4 * 4
Test #11:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
11
output:
Possible 5 1 1 1 2 2 1 1 1 2 2 1 1 1 3 3 4 5 6 3 3 7 8 9 10 11
result:
ok answer 11 squares of 3 different sizes in total 5 * 5
Test #12:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
12
output:
Possible 6 1 1 2 2 3 3 1 1 2 2 3 3 4 4 5 5 6 6 4 4 5 5 6 6 7 7 8 8 9 10 7 7 8 8 11 12
result:
ok answer 12 squares of 2 different sizes in total 6 * 6
Test #13:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
13
output:
Possible 4 1 1 2 3 1 1 4 5 6 7 8 9 10 11 12 13
result:
ok answer 13 squares of 2 different sizes in total 4 * 4
Test #14:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
14
output:
Possible 5 1 1 1 2 2 1 1 1 2 2 1 1 1 3 4 5 6 7 8 9 10 11 12 13 14
result:
ok answer 14 squares of 3 different sizes in total 5 * 5
Test #15:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
15
output:
Possible 6 1 1 2 2 3 3 1 1 2 2 3 3 4 4 5 5 6 6 4 4 5 5 6 6 7 7 8 9 10 11 7 7 12 13 14 15
result:
ok answer 15 squares of 2 different sizes in total 6 * 6
Test #16:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
16
output:
Possible 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
result:
ok answer 16 squares of 1 different sizes in total 4 * 4
Test #17:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
17
output:
Possible 5 1 1 1 2 3 1 1 1 4 5 1 1 1 6 7 8 9 10 11 12 13 14 15 16 17
result:
ok answer 17 squares of 2 different sizes in total 5 * 5
Test #18:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
18
output:
Possible 6 1 1 2 2 3 3 1 1 2 2 3 3 4 4 5 5 6 6 4 4 5 5 6 6 7 8 9 10 11 12 13 14 15 16 17 18
result:
ok answer 18 squares of 2 different sizes in total 6 * 6
Test #19:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
19
output:
Possible 5 1 1 2 2 3 1 1 2 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
result:
ok answer 19 squares of 2 different sizes in total 5 * 5
Test #20:
score: -100
Wrong Answer
time: 0ms
memory: 3632kb
input:
20
output:
Possible 7 1 1 1 2 2 3 3 1 1 1 2 2 3 3 1 1 1 4 4 5 5 6 6 7 7 4 5 5 6 6 7 7 8 8 9 10 11 12 13 8 8 14 15 16 17 18 19 20 21
result:
wrong answer Illegal construction