QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470481 | #6398. Puzzle: Tapa | lllei# | WA | 0ms | 3832kb | C++20 | 5.5kb | 2024-07-10 14:05:27 | 2024-07-10 14:05:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> s(2 * n - 1);
vector ans(2 * n - 1, vector<char>(2 * m - 1, '#'));
for (int i = 0; i < 2 * n - 1; ++i) {
cin >> s[i];
}
for (int i = 0; i < 2 * n - 1; i += 2) {
for (int j = 0; j < 2 * m - 1; j += 2) {
ans[i][j] = s[i][j];
}
}
vector<int> a;
vector<int> b;
auto check = [&](int x, int y) {
if (x < 0 || x >= 2 * n - 1 || y < 0 || y >= 2 * m - 1) {
return false;
}
if (s[x][y] == '2' || s[x][y] == '4' || s[x][y] == '7') {
return true;
}
return false;
};
auto getId = [&](int x, int y) {
return (x / 2) * m + y / 2;
};
auto getRid = [&](int a) {
int x = a / m;
int y = a % m;
return array<int, 2>{x * 2, y * 2};
};
vector<vector<int>> e(n * m);
int sum = 0;
for (int i = 0; i < 2 * n - 1; i += 2) {
for (int j = 0; j < 2 * m - 1; j += 2) {
if (check(i, j)) {
sum++;
if ((i / 2 + j / 2) & 1) {
b.push_back(getId(i, j));
} else {
a.push_back(getId(i, j));
}
}
}
}
for (int i = 0; i < 2 * n - 1; i += 2) {
int j;
if ((i / 2) & 1) {
j = 2;
} else {
j = 0;
}
for (; j < 2 * m - 1; j += 4) {
int u = getId(i, j);
if (s[i][j] == '2') {
if (check(i - 2, j)) {
int v = getId(i - 2, j);
e[u].push_back(v);
}
if (check(i + 2, j)) {
int v = getId(i + 2, j);
e[u].push_back(v);
}
if (check(i, j - 2)) {
int v = getId(i, j - 2);
e[u].push_back(v);
}
if (check(i, j + 2)) {
int v = getId(i, j + 2);
e[u].push_back(v);
}
}
if (s[i][j] == '4') {
if (i == 0 || i == 2 * n - 1) {
if (check(i, j - 2)) {
int v = getId(i, j - 2);
e[u].push_back(v);
}
if (check(i, j + 2)) {
int v = getId(i, j + 2);
e[u].push_back(v);
}
} else {
if (check(i + 2, j)) {
int v = getId(i + 2, j);
e[u].push_back(v);
}
if (check(i - 2, j)) {
int v= getId(i - 2, j);
e[u].push_back(v);
}
}
}
if (s[i][j] == '7') {
if (check(i + 2, j)) {
if (i + 2 == 0 || i + 2 == 2 * n - 1) {
continue;
}
int v = getId(i + 2, j);
e[u].push_back(v);
}
if (check(i - 2, j)) {
if (i - 2 == 0 || i - 2 == 2 * n - 1) {
continue;
}
int v= getId(i - 2, j);
e[u].push_back(v);
}
if (check(i, j - 2)) {
if (j - 2 == 0 || j - 2 == 2 * m - 1) {
continue;
}
int v = getId(i, j - 2);
e[u].push_back(v);
}
if (check(i, j + 2)) {
if (j + 2 == 0 || j + 2 == 2 * m - 1) {
continue;
}
int v = getId(i, j + 2);
e[u].push_back(v);
}
}
}
}
vector<int> pa(n * m, -1), pb(n * m , -1);
vector<int> vis(n * m, 0);
int dfn = 0;
int res = 0;
auto dfs = [&](auto &&self, int u) -> bool {
vis[u] = dfn;
for (int v : e[u]) {
if (pb[v] == -1) {
pb[v] = u;
pa[u] = v;
return true;
}
}
for (int v : e[u]) {
if (vis[pb[v]] != dfn && self(self, pb[v])) {
pa[u] = v;
pb[v] = u;
return true;
}
}
return false;
};
while (true) {
dfn++;
int cnt = 0;
for (int i : a) {
if (pa[i] == -1 && dfs(dfs, i)) {
cnt++;
}
}
if (cnt == 0) {
break;
}
res += cnt;
}
if (res * 2 == sum) {
cout << "YES\n";
for (int u : a) {
int v = pa[u];
auto [x1, y1] = getRid(u);
auto [x2, y2] = getRid(v);
ans[(x1 + x2) / 2][(y1 + y2) / 2] = '.';
}
for (int i = 0; i < 2 * n - 1; ++i) {
for (int j = 0; j < 2 * m - 1; ++j) {
cout << ans[i][j];
}
cout << '\n';
}
} else {
cout << "NO\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 3 2.4.3 ..... 5.8.5 ..... 3.5.3
output:
YES 2.4#3 ##### 5#8#5 ##### 3#5#3
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
3 3 3.4.3 ..... 5.7.5 ..... 3.5.3
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 2 2.2 ... 2.2
output:
YES 2#2 .#. 2#2
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 50 2.4.4.4.4.5.5.5.5.5.5.5.5.4.5.5.4.4.5.5.5.5.4.5.5.5.5.5.4.4.5.4.5.5.5.5.5.5.5.5.5.5.5.4.4.5.5.4.5.3 ................................................................................................... 2.5.5.4.4.5.5.5.4.4.5.5.5.4.5.5.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.5.4.4.5.5.5.5.4...
output:
NO
result:
ok Correct.
Test #5:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 50 2.4.4.5.5.5.5.5.5.5.5.5.4.4.5.5.5.5.4.4.5.5.4.4.5.5.5.4.5.4.4.4.5.4.4.5.4.4.5.5.5.5.4.4.5.5.5.5.5.2 ................................................................................................... 3.5.4.5.5.5.5.5.5.5.5.5.5.5.4.5.5.5.5.4.5.5.5.5.4.4.5.4.5.4.5.5.5.5.5.4.4.5.5.5.4.4.5.5.5.5.5.4...
output:
NO
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
50 2 3.2 ... 5.4 ... 5.5 ... 4.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.4 ... 5.4 ... 4.4 ... 5.5 ... 5.5 ... 4.4 ... 5.4 ... 5.4 ... 5.5 ... 4.5 ... 4.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ......
output:
NO
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
50 2 3.3 ... 5.4 ... 5.4 ... 5.4 ... 5.4 ... 5.5 ... 4.4 ... 4.4 ... 5.5 ... 4.4 ... 5.5 ... 5.5 ... 5.5 ... 5.5 ... 4.5 ... 5.5 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.4 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.5 ... 4.5 ... 4.5 ... 4.5 ... 4.5 ... 5.5 ... 5.4 ... 5.4 ... 5.5 ... 5.5 ... 4.4 ... 4.4 ......
output:
NO
result:
ok Correct.
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3832kb
input:
3 50 3.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.4.4.5.5.5.5.4.4.5.5.5.5.5.5.5.5.4.4.5.5.4.4.5.4.4.5.3 ................................................................................................... 4.8.8.8.8.8.8.8.8.8.8.8.8.8.8.7.7.7.7.7.7.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.7.7.8...
output:
NO
result:
wrong answer Jury has answer but participant has not.