QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253248 | #6398. Puzzle: Tapa | supepapupu | WA | 3ms | 14660kb | C++17 | 3.5kb | 2023-11-16 20:11:10 | 2023-11-16 20:11:11 |
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}, {1, 1}, {1, -1}, {-1, 1}, {-1, -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 get(int x, int y) {
return (x - 1) * (m * 2 - 1) + y - 1;
}
pii neib(int i, int j) {
pii res;
for (int k = 0; k < 8; ++k) {
int x = i + d[k][0], y = j + d[k][1];
if (!x || !y || x > n * 2 - 1 || y > m * 2 - 1) continue;
if (x == 1 || y == 1 || x == n * 2 - 1 || y == m * 2 - 1) {
if (res.x == 0) res.x = get(x, y);
else res.y = get(x, y);
}
}
return res;
}
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;
for (int i = 1; i <= n * 2 - 1; ++i) for (int j = 1; j <= m * 2 - 1; ++j) {
if (g[i][j] == '3' || g[i][j] == '5' || g[i][j] == '8') {
vector<int> adj;
for (int k = 0; k < 8; ++k) {
int x = i + d[k][0], y = j + d[k][1];
if (!x || !y || x > n * 2 - 1 || y > m * 2 - 1) continue;
adj.emplace_back(get(x, y));
}
for (int l: adj) G[l * 2].emplace_back(l * 2 + 1);
} else if (g[i][j] == '2' || g[i][j] == '4') {
auto[l, r] = neib(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);
vector<int> adj;
for (int k = 0; k < 8; ++k) {
int x = i + d[k][0], y = j + d[k][1];
if (!x || !y || x > n * 2 - 1 || y > m * 2 - 1) continue;
if (get(x, y) == l || get(x, y) == r) continue;
adj.emplace_back(get(x, y));
}
for (int l: adj) G[l * 2].emplace_back(l * 2 + 1);
} else if (g[i][j] == '7') {
vector<int> adj;
for (int k = 0; k < 8; ++k) {
int x = i + d[k][0], y = j + d[k][1];
if (!x || !y || x > n * 2 - 1 || y > m * 2 - 1) continue;
adj.emplace_back(get(x, y));
}
for (int l: adj) for (int r: adj) if (l != r)
G[l * 2].emplace_back(r * 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: 3ms
memory: 13024kb
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: 14424kb
input:
3 3 3.4.3 ..... 5.7.5 ..... 3.5.3
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 2ms
memory: 11520kb
input:
2 2 2.2 ... 2.2
output:
YES 2.2 ### 2.2
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 0ms
memory: 14348kb
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: 2ms
memory: 14660kb
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: 2ms
memory: 11364kb
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: 12812kb
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: 2ms
memory: 13176kb
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:
wrong answer Clue not satisfied at (3,31)