QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689194 | #6398. Puzzle: Tapa | MiniLong | WA | 1ms | 10092kb | C++14 | 5.4kb | 2024-10-30 15:46:22 | 2024-10-30 15:46:24 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1005, M = 1e6 + 5, inf = 0x3f3f3f3f;
int n, m, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
char ch[N][N];
int code(int x, int y){return (x - 1) * m + y;}
bool check(int x, int y){
x = 2 * x - 1, y = 2 * y - 1;
return ch[x][y] != '8' && ch[x][y] != '5' && ch[x][y] != '3';
}
namespace Flow{
int s, t, ecnt = 1, head[M], cur[M];
struct edge{
int v, w, nxt;
}e[M << 1];
void add(int u, int v, int w){
e[++ecnt] = edge{v, w, head[u]}, head[u] = ecnt;
e[++ecnt] = edge{u, 0, head[v]}, head[v] = ecnt;
}
int num[M];
bool bfs(int s, int t){
fill(num + s, num + t + 1, 0);
queue<int> q;
q.push(s), cur[s] = head[s], num[s] = 1;
while(q.size()){
int u = q.front(); q.pop();
_rev(i, u){
int v = e[i].v;
if(!num[v] && e[i].w){
num[v] = num[u] + 1;
cur[v] = head[v];
q.push(v);
}
}
}
return num[t];
}
int dfs(int u, int in){
int out = 0;
if(u == t) return in;
for(int i = cur[u]; i && in; i = e[i].nxt){
int v = e[i].v;
cur[u] = i;
if(e[i].w && num[v] == num[u] + 1){
int d = dfs(v, min(e[i].w, in));
e[i].w -= d, e[i ^ 1].w += d;
in -= d, out += d;
}
}
if(!out) num[u] = 0;
return out;
}
int Dinic(){
int Flow = 0;
while(bfs(s, t)) Flow += dfs(s, inf);
return Flow;
}
}
using namespace Flow;
map<PII, PII> mp;
int main(){
read(n, m);
_rep(i, 1, n * 2 - 1) scanf("%s", ch[i] + 1);
int cnt = 0;
s = 0, t = 2 * n * m + 1;
_rep(i, 1, n){
_rep(j, 1, m){
cnt += check(i, j);
if((i + j) & 1) continue;
if(check(i, j)){
_rep(k, 0, 3){
int x = i + dx[k], y = j + dy[k];
if(x < 1 || x > n || y < 1 || y > m) continue;
if(!check(x, y) || ch[2 * i - 1][2 * j - 1] == '7' && ch[2 * x - 1][2 * y - 1] != '7' || ch[2 * i - 1][2 * j - 1] != '7' && ch[2 * x - 1][2 * y - 1] == '7') continue;
int u = code(i, j), v = code(x, y);
add(u, v + n * m, 1);
mp[{u, v + n * m}] = {2 * i - 1 + dx[k], 2 * j - 1 + dy[k]};
}
}
}
}
_rep(i, 1, n * m) add(s, i, 1), add(n * m + i, t, 1);
if((cnt & 1) || Dinic() != cnt / 2) return puts("NO"), 0;
_rep(i, 1, 2 * n - 1) _rep(j, 1, 2 * m - 1) if(ch[i][j] == '.') ch[i][j] = '#';
_rep(i, 1, n){
_rep(j, 1, m){
if(!check(i, j)) continue;
int u = code(i, j), v = 0;
_rev(k, u){
if(e[k].v == s || e[k].w) continue;
v = e[k].v;
}
PII cur = mp[{u, v}];
ch[cur.fi][cur.se] = '.';
}
}
puts("YES");
_rep(i, 1, 2 * n - 1){
_rep(j, 1, 2 * m - 1) putchar(ch[i][j]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 10092kb
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: 1ms
memory: 9796kb
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: 9816kb
input:
2 2 2.2 ... 2.2
output:
YES 2.2 ### 2.2
result:
ok Correct.
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 9748kb
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:
YES 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#...
result:
wrong answer Clue not satisfied at (1,27), non-consecutive shaded cells