QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#181194 | #7218. The Ultimate Duel | ckiseki# | WA | 2ms | 5652kb | C++17 | 4.3kb | 2023-09-16 16:30:53 | 2023-09-16 16:30:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1025;
int vis[maxn][maxn];
int z = 0;
int c = 0;
bool dfs(int len, int target, int rest, int i, int j) {
if (++c >= 1e6) return false;
if (target > rest) {
return false;
}
if (j == len) i = i + 1, j = 0;
if (i == len) {
if (target == rest) {
return true;
} else {
return false;
}
}
if (target == rest) {
if (!vis[i][j]) vis[i][j] = ++z;
return dfs(len, target, rest, i, j + 1);
}
if (!vis[i][j]) {
// rest - s * s + 1 == target;
// int S = rest + 1 - target;
// int s = sqrt(S);
// if (s * s == S) {
// ++z;
// for (int x = 0; x < s; x++)
// for (int y = 0; y < s; y++)
// vis[i + x][j + y] = z;
// return true;
// }
++z;
for (int s = 1; s <= len && j + s <= len && i + s <= len; s++) {
for (int x = 0; x < s; x++)
vis[i + s - 1][j + x] = z;
for (int x = 0; x < s; x++)
vis[i + x][j + s - 1] = z;
if (dfs(len, target, rest - s * s + 1, i, j + s)) return true;
}
for (int s = 1; s <= len && j + s <= len && i + s <= len; s++) {
for (int x = 0; x < s; x++)
vis[i + s - 1][j + x] = 0;
for (int x = 0; x < s; x++)
vis[i + x][j + s - 1] = 0;
}
--z;
}
return dfs(len, target, rest, i, j + 1);
}
vector<vector<int>> ans[maxn];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
/*
bs[0][0] = true;
for (int c = 0; c < 100; c++) {
for (int i = 1; i <= 100; i++) {
bs[c + 1] |= bs[c] << (i * i);
}
}
for (int c = 1; c <= 100; c++) {
bool A = false;
for (int i = 1; i <= 100; i++) {
A |= bs[c][i * i];
}
cout << c << ' ' << boolalpha << A << endl
}
*/
const auto tryit = [&](int n) {
for (int i = 0; i < 200; i++)
for (int j = 0; j < 200; j++)
vis[i][j] = 0;
z = 0;
c = 0;
for (int len = ceil(sqrt(n)); len <= 200; len++) {
if (dfs(len, n, len * len, 0, 0)) {
ans[n] = vector(len, vector(len, 0));
for (int i = 0; i < len; i++)
for (int j = 0; j < len; j++) {
ans[n][i][j] = vis[i][j];
// cout << vis[i][j] + 1 << (j+1==len ? '\n' : ' ');
}
return true;
}
}
return false;
};
if (1) {
const int n = 14;
tryit(n);
const int len = ans[n].size();
cout << len << '\n';
for (int i = 0; i < len; i++) {
for (int j = 0; j < len; j++) {
cout << ans[n][i][j] << (j+1==len ? '\n' : ' ');
}
}
return 0;
}
const auto from_i = [&](int n, int i) {
int len = ans[n - i].size();
int C = -1;
pair<int,int> pos;
auto &A = ans[n - i];
const auto ok = [&len](int x, int y) { return x >= 0 && x < len && y >= 0 && y < len; };
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
for (int x = 0; x < len && C == -1; x++) {
for (int y = 0; y < len && C == -1; y++) {
bool flag = true;
for (int k = 0; k < 4; k++)
if (ok(x + dx[k], y + dy[k]))
flag &= (A[x + dx[k]][y + dy[k]] != A[x][y]);
if (flag) {
if (i == 0) C = 1;
else if (i == 3) C = 2;
else if (i == 5) C = 3;
pos = {x, y};
break;
}
}
}
if (C == -1) return false;
if (i) ans[n] = vector(len * C, vector(len * C, 0));
for (int x = 0; x < len * C; x++) {
for (int y = 0; y < len * C; y++) {
ans[n][x][y] = ans[n - i][x / C][y / C];
}
}
int z = 0;
for (int a = 0; a < len; a++)
for (int b = 0; b < len; b++)
z = max(z, ans[n - i][a][b]);
auto [x, y] = pos;
if (i == 3 || i == 5) {
for (int a = 0; a < C; a++)
for (int b = 0; b < C; b++)
if (a >= i / 2 || b >= i / 2)
ans[n][x + a][x + b] = ++z;
}
return true;
};
const auto gao = [&](auto self, int n) {
for (int i: {0, 3, 5}) {
if (tryit(n - i) && from_i(n, i)) {
return true;
}
}
for (int i: {0, 3, 5})
if (self(self, n - i) && from_i(n, i)) {
return true;
}
return false;
};
int n;
cin >> n;
bool res = gao(gao, n);
int len = ans[n].size();
cout << len << '\n';
for (int i = 0; i < len; i++) {
for (int j = 0; j < len; j++) {
cout << ans[n][i][j] << (j+1==len ? '\n' : ' ');
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5652kb
input:
R S
output:
5 1 2 3 4 5 6 7 8 9 10 11 12 13 13 13 14 15 16 17 17 18 19 13 17 17
result:
wrong answer 1st words differ - expected: 'TankEngineer', found: '5'