QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#228140 | #6398. Puzzle: Tapa | kiwiHM# | WA | 3ms | 12552kb | C++14 | 4.8kb | 2023-10-28 12:37:43 | 2023-10-28 12:37:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int maxv = 2e5;
vector<int> g[maxv];
namespace Tarjan{
int clk, top, scc;
int low[maxv], dfn[maxv], stk[maxv], ins[maxv], col[maxv];
inline void tarjan(int u){
low[u] = dfn[u] = clk++;
stk[++top] = u;
ins[u] = true;
for(auto 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(low[u] == dfn[u]){
for(int v = stk[top]; v != u; v = stk[--top]){
ins[v] = false;
col[v] = scc;
}
col[u] = scc;
ins[u] = false;
--top;
++scc;
}
}
inline void work(){
memset(dfn, -1, sizeof(dfn));
for(int u = 0; u < maxv; ++u) if(!~dfn[u])
tarjan(u);
for(int u = 0; u < (maxv >> 1); ++u){
if(col[u << 1] == col[u << 1 | 1]){
// printf("u = %d col %d %d\n", u, col[u << 1], col[u << 1 | 1]);
puts("NO");
exit(0);
}
}
}
}
int n, m, tot;
char buf[maxn][maxn];
inline int solve(vector<int> vec){
if(vec.size() == 1) return vec[0];
vector<int> L, R;
for(int i = 0; i < vec.size(); ++i){
if(i < vec.size() / 2) L.push_back(vec[i]);
else R.push_back(vec[i]);
}
int u = solve(L), v = solve(R);
int w = tot++;
g[u << 1 | 1].push_back(v << 1);
g[v << 1 | 1].push_back(u << 1);
g[w << 1].push_back(u << 1);
g[w << 1].push_back(v << 1);
g[u << 1 | 1].push_back(w << 1 | 1);
g[v << 1 | 1].push_back(w << 1 | 1);
// for(auto p: vec) printf("%d ", p); puts("");
// printf("solve w = %d\n", w);
return w;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 0; i < n * 2 - 1; ++i){
scanf("%s", buf[i]);
}
tot = (n * 2 - 1) * (m * 2 - 1);
for(int i = 0; i < n * 2 - 1; i += 2){
for(int j = 0; j < m * 2 - 1; j += 2){
if(buf[i][j] == '2'){
int u, v, w = 0;
if(i == 0) u = (i + 1) * (m * 2 - 1) + j, w += (i + 1) * (m * 2 - 1);
else u = (i - 1) * (m * 2 - 1) + j, w += (i - 1) * (m * 2 - 1);
if(j == 0) v = i * (m * 2 - 1) + (j + 1), w += j + 1;
else v = i * (m * 2 - 1) + (j - 1), w += j - 1;
g[u << 1].push_back(v << 1 | 1);
g[v << 1 | 1].push_back(u << 1);
g[v << 1].push_back(u << 1 | 1);
g[u << 1 | 1].push_back(v << 1);
g[w << 1].push_back(w << 1 | 1);
}
else if(buf[i][j] == '4'){
int u, v;
if(i == 0) u = i * (m * 2 - 1) + (j - 1), v = i * (m * 2 - 1) + (j + 1);
else u = (i - 1) * (m * 2 - 1) + j, v = (i + 1) * (m * 2 - 1) + j;
g[u << 1].push_back(v << 1 | 1);
g[v << 1 | 1].push_back(u << 1);
g[v << 1].push_back(u << 1 | 1);
g[u << 1 | 1].push_back(v << 1);
for(int t = -1; t <= 1; ++t){
int w;
if(i == 0) w = (i + 1) * (m * 2 - 1) + (j + t);
else if(i == n * 2 - 2) w = (i - 1) * (m * 2 - 1) + (j + t);
else if(j == 0) w = (i + t) * (m * 2 - 1) + (j + 1);
else w = (i + t) * (m * 2 - 1) + (j - 1);
g[w << 1].push_back(w << 1 | 1);
}
}
else if(buf[i][j] == '7'){
vector<int> vec;
for(int p = -1; p <= 1; ++p) for(int q = -1; q <= 1; ++q)
if(!(p == 0 && q == 0)) vec.push_back((i + p) * (m * 2 - 1) + (q + j));
int w = solve(vec);
g[w << 1].push_back(w << 1 | 1);
}
else if(isdigit(buf[i][j])){
for(int p = -1; p <= 1; ++p) for(int q = -1; q <= 1; ++q){
if(!(p == 0 && q == 0) && i + p >= 0 && i + p < n * 2 - 1 && j + q >= 0 && j + q < m * 2 - 1){
int u = (i + p) * (m * 2 - 1) + (j + q);
g[u << 1].push_back(u << 1 | 1);
}
}
}
}
}
Tarjan::work();
puts("YES");
for(int i = 0; i < (n * 2 - 1); ++i){
for(int j = 0; j < (m * 2 - 1); ++j){
if(isdigit(buf[i][j])) putchar(buf[i][j]);
else{
int u = i * (m * 2 - 1) + j;
if(Tarjan::col[u << 1] < Tarjan::col[u << 1 | 1]) putchar('.');
else putchar('#');
}
}
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12472kb
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: 3ms
memory: 12308kb
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: 12288kb
input:
2 2 2.2 ... 2.2
output:
YES 2.2 ### 2.2
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 2ms
memory: 12552kb
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: 12288kb
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: 12328kb
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: 3ms
memory: 12332kb
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: 12552kb
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.