QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253301 | #6398. Puzzle: Tapa | supepapupu | WA | 3ms | 14752kb | C++17 | 3.9kb | 2023-11-16 21:02:49 | 2023-11-16 21:02:50 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define el '\n'
#define debug(x) cout << #x << ": " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;
void quit() {
cout << "NO\n";
exit(0);
}
int d[][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
char g[110][110];
vector<int> G[N];
int dfn[N], low[N], stk[N], ins[N];
int top, scc_cnt, id[N], ts;
void tarjan(int u) {
dfn[u] = low[u] = ++ts;
stk[++top] = u, ins[u] = 1;
for (int v : G[u])
if (!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if (ins[v]) low[u] = min(low[u], dfn[v]);
if (dfn[u] == low[u]) {
++scc_cnt;
int y;
do {
y = stk[top--];
ins[y] = 0;
id[y] = scc_cnt;
} while (y != u);
}
}
int n, m;
int small(int x, int y) {
char c = g[x][y];
return c == '2' || c == '4' || c == '7';
}
int get(int x, int y) {
return (x - 1) * (m * 2 - 1) + y - 1;
}
void wk(int xl, int xr, int yl, int yr) {
auto find_adj = [&](int i, int j)->vector<int> {
vector<int> res;
for (int k = 0; k < 4; ++k) {
int x = i + d[k][0], y = j + d[k][1];
if (x < xl || y < yl || x > xr || y > yr) continue;
if (x == xl || y == yl || x == xr || y == yr) {
res.emplace_back(get(x, y));
}
}
return res;
};
if (xl > xr || yl > yr) return;
if (xl == xr || yl == yr) {
for (int i = xl; i <= xr; i += 2) for (int j = yl; j <= yr; j += 2) {
auto adj = find_adj(i, j);
if (adj.empty()) {
if (small(i, j)) quit();
continue;
}
if (adj.size() == 1) {
int t = adj.back();
G[t * 2 + small(i, j)].emplace_back(t * 2 + !small(i, j));
} else {
assert(adj.size() == 2);
int l = adj[0], r = adj[1];
if (small(i, j)) {
G[l * 2].emplace_back(r * 2 + 1), G[l * 2 + 1].emplace_back(r * 2);
G[r * 2].emplace_back(l * 2 + 1), G[r * 2 + 1].emplace_back(l * 2);
} else {
G[l * 2].emplace_back(l * 2 + 1), G[r * 2].emplace_back(r * 2 + 1);
}
}
}
return;
}
for (int i = xl + 1; i <= xr - 1; ++i) for (int j = yl + 1; j <= yr - 1; ++j)
if (i == xl + 1 || i == xr - 1 || j == yl + 1 || j == yr - 1) {
g[i][j] = '#';
}
for (int i = xl; i <= xr; i += 2) for (int j = yl; j <= yr; j += 2) {
if (i == xl || i == xr || j == yl || j == yr) {
auto adj = find_adj(i, j);
assert(adj.size() == 2);
int l = adj[0], r = adj[1];
if (small(i, j)) {
G[l * 2].emplace_back(r * 2 + 1), G[l * 2 + 1].emplace_back(r * 2);
G[r * 2].emplace_back(l * 2 + 1), G[r * 2 + 1].emplace_back(l * 2);
} else {
G[l * 2].emplace_back(l * 2 + 1), G[r * 2].emplace_back(r * 2 + 1);
}
}
}
wk(xl + 2, xr - 2, yl + 2, yr - 2);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n * 2 - 1; ++i) cin >> g[i] + 1;
wk(1, n * 2 - 1, 1, m * 2 - 1);
for (int i = 0; i <= (n * 2 - 1) * (m * 2 - 1) * 2 - 1; ++i)
if (!dfn[i]) tarjan(i);
for (int i = 0; i < (n * 2 - 1) * (m * 2 - 1); ++i) {
if (id[i * 2] == id[i * 2 + 1]) quit();
if (id[i * 2 + 1] < id[i * 2]) {
int x = i / (m * 2 - 1) + 1, y = i % (m * 2 - 1) + 1;
g[x][y] = '#';
}
}
cout << "YES\n";
for (int i = 1; i <= n * 2 - 1; ++i) cout << g[i] + 1 << el;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12988kb
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: 2ms
memory: 11072kb
input:
3 3 3.4.3 ..... 5.7.5 ..... 3.5.3
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 3ms
memory: 13496kb
input:
2 2 2.2 ... 2.2
output:
YES 2.2 ### 2.2
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 2ms
memory: 11396kb
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: 14404kb
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: 14588kb
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: 14752kb
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: 0
Accepted
time: 3ms
memory: 12716kb
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:
YES 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#...
result:
ok Correct.
Test #9:
score: 0
Accepted
time: 0ms
memory: 11352kb
input:
3 50 2.4.4.4.5.4.4.4.4.4.4.5.5.4.4.5.5.4.4.5.5.5.4.4.5.5.5.4.4.5.5.4.4.4.4.5.5.5.5.5.5.4.4.5.5.5.5.4.4.3 ................................................................................................... 5.7.7.8.7.7.7.7.8.8.8.8.7.7.8.7.7.8.8.8.8.7.7.8.8.8.7.7.8.7.7.8.8.8.8.7.7.8.8.7.7.8.8.8.7.7.8.8...
output:
YES 2.4#4.4#5#4.4#4.4#4.4#5#5#4.4#5#5#4.4#5#5#5#4.4#5#5#5#4.4#5#5#4.4#4.4#5#5#5#5#5#5#4.4#5#5#5#5#4.4#3 ################################################################################################### 5#7.7#8#7.7#7.7#8#8#8#8#7.7#8#7.7#8#8#8#8#7.7#8#8#8#7.7#8#7.7#8#8#8#8#7.7#8#8#7.7#8#8#8#7.7#8#8#...
result:
ok Correct.
Test #10:
score: 0
Accepted
time: 2ms
memory: 12968kb
input:
50 3 3.5.3 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.4 ..... 5.8.4 ..... 4.8.5 ..... 4.7.5 ..... 5.7.5 ..... 5.8.5 ..... 5.8.4 ..... 5.8.4 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ..... 4.8.5 ..... 4.7.5 ..... 5.7.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ....
output:
YES 3#5#3 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#4 ####. 5#8#4 ##### 4#8#5 .#### 4#7#5 ##.## 5#7#5 ##### 5#8#5 ##### 5#8#4 ####. 5#8#4 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##### 4#8#5 .#### 4#7#5 ##.## 5#7#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##...
result:
ok Correct.
Test #11:
score: 0
Accepted
time: 2ms
memory: 14344kb
input:
50 3 2.4.3 ..... 4.8.5 ..... 4.8.5 ..... 5.8.5 ..... 4.7.4 ..... 4.7.4 ..... 4.8.5 ..... 4.8.4 ..... 5.8.4 ..... 4.7.5 ..... 4.7.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.4 ..... 5.8.4 ..... 5.8.5 ..... 5.8.5 ..... 5.7.5 ..... 5.7.5 ..... 5.8.5 ..... 5.8.5 ..... 5.8.5 ..... 4.8.5 ..... 4.7.5 ..... 4.7.4 ....
output:
YES 2.4#3 ##### 4#8#5 .#### 4#8#5 ##### 5#8#5 ##### 4#7#4 .#.#. 4#7#4 ##### 4#8#5 .#### 4#8#4 ####. 5#8#4 ##### 4#7#5 .#.## 4#7#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#4 ####. 5#8#4 ##### 5#8#5 ##### 5#8#5 ##### 5#7#5 ##.## 5#7#5 ##### 5#8#5 ##### 5#8#5 ##### 5#8#5 ##### 4#8#5 .#### 4#7#5 ##.## 4#7#4 .#...
result:
ok Correct.
Test #12:
score: -100
Wrong Answer
time: 0ms
memory: 11564kb
input:
10 10 2.4.4.4.5.5.4.4.5.2 ................... 5.7.8.8.7.8.7.7.8.4 ................... 4.7.8.8.7.8.8.8.8.5 ................... 4.8.8.8.7.7.8.8.8.4 ................... 5.8.7.7.7.7.8.8.7.4 ................... 4.7.7.8.8.8.8.8.7.4 ................... 4.8.7.8.8.7.7.7.8.4 ................... 5.8.7.8.8.7.8....
output:
NO
result:
wrong answer Jury has answer but participant has not.