QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#544423 | #9224. Express Eviction | Fork512Hz | WA | 1ms | 3708kb | C++20 | 3.4kb | 2024-09-02 16:27:13 | 2024-09-02 16:27:13 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<utility>
#include<vector>
#include<functional>
#include<queue>
#include<set>
#include<cmath>
using namespace std;
typedef pair<long long, long long> pii;
typedef vector<long long> vll;
typedef long long ll;
typedef long long i64;
#define DEBUG
#ifdef DEBUG
const long long N = 31000;
#endif
#ifndef DEBUG
const long long N = 31000;
#endif
// const ll M = 998244353;
ll n, m;
const int INF = 0x7fffffff;
const int IN = 10000000;
struct MF {
struct edge {
int v, nxt, cap, flow;
} e[N];
int fir[N], cnt = 0;
int n, S, T;
ll maxflow = 0;
int dep[N], cur[N];
void init() {
memset(fir, -1, sizeof fir);
cnt = 0;
}
void addedge(int u, int v, int w) {
// cout << u << ' ' << v << ' ' << w << ' ' << cnt << '\n';
e[cnt] = {v, fir[u], w, 0};
fir[u] = cnt++;
e[cnt] = {u, fir[v], 0, 0};
fir[v] = cnt++;
}
bool bfs() {
queue<int> q;
memset(dep, 0, sizeof(int) * (n + 1));
dep[S] = 1;
q.push(S);
while (q.size()) {
int u = q.front();
q.pop();
for (int i = fir[u]; ~i; i = e[i].nxt) {
int v = e[i].v;
if ((!dep[v]) && (e[i].cap > e[i].flow)) {
dep[v] = dep[u] + 1;
q.push(v);
}
}
}
return dep[T];
}
int dfs(int u, int flow) {
if ((u == T) || (!flow)) return flow;
int ret = 0;
for (int& i = cur[u]; ~i; i = e[i].nxt) {
int v = e[i].v, d;
if ((dep[v] == dep[u] + 1) &&
(d = dfs(v, min(flow - ret, e[i].cap - e[i].flow)))) {
ret += d;
e[i].flow += d;
e[i ^ 1].flow -= d;
if (ret == flow) return ret;
}
}
return ret;
}
void dinic() {
while (bfs()) {
memcpy(cur, fir, sizeof(int) * (n + 1));
maxflow += dfs(S, INF);
}
}
};
string s[55];
MF maxflow;
inline ll inid(ll x, ll y)
{
return x * m + y;
}
inline ll outid(ll x, ll y)
{
return x * m + y + n*m;
}
int main()
{
#ifdef DEBUG
freopen("1.txt", "r", stdin);
#endif
#ifndef DEBUG
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#endif
cin >> n >>m;
const ll SRC = 2*n*m;
const ll DST = SRC + 1;
maxflow.init();
maxflow.n = n*m*2 + 2;
maxflow.S = SRC;
maxflow.T = DST;
for(ll i=0; i<n; i++)
cin >> s[i];
for(ll i=0; i<n; i++)
for(ll j=0; j<m; j++) if(s[i][j] == '#')
{
maxflow.addedge(inid(i, j), outid(i, j), 1);
if(j == 0 || i == n-1) // Bottom left
maxflow.addedge(SRC, inid(i, j), IN);
if(j == m-1 || i == 0) // Top right
maxflow.addedge(outid(i, j), DST, IN);
for(ll di=0; di<=2; di++) // Search resident pairs in 5*5
{
if(i - di < 0) break;
for(ll dj=(di==0? 1: -2); dj<=2; dj++)
{
if(j - dj < 0) break;
if(j - dj >= m) continue;
if(s[i-di][j-dj] == '#')
{
maxflow.addedge(outid(i, j), inid(i-di, j-dj), IN);
maxflow.addedge(outid(i-di, j-dj), inid(i, j), IN);
}
}
}
}
maxflow.dinic();
cout << maxflow.maxflow << '\n';
return 0;
}
/*BEFORE SUBMISSION:
1. remove #define DEBUG
2. check data constraints
3. check memory reset for multitest
4. check integer overflow
5. parenthesize all bitwise operations
6. run all sample tests in random order
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3708kb
input:
4 6 .##... .#.... ##.... ....#.
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'