QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#677282 | #9224. Express Eviction | 11d10xy | WA | 1ms | 9956kb | C++14 | 1.9kb | 2024-10-26 10:55:38 | 2024-10-26 10:55:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace mf{
constexpr int N=100010,M=1000010;
int head[N],cur[N],d[N],cap[M],ver[M],nex[M],n,s,t,tot=1;
queue<int>q;
inline void add(int u,int v,int c){
nex[++tot]=head[u],cap[tot]=c,ver[tot]=v,head[u]=tot;
nex[++tot]=head[v],cap[tot]=0,ver[tot]=u,head[v]=tot;
}
bool bfs(){
for(int i=1;i<=n;i++)d[i]=-1,cur[i]=head[i];
d[s]=0,q.push(s);
for(;!q.empty();){
int u=q.front();q.pop();
for(int e=head[u];e;e=nex[e]){
int c=cap[e],v=ver[e];
if(c&&d[v]==-1){
d[v]=d[u]+1,q.push(v);
}
}
}return d[t]!=-1;
}
int dinic(int u,int flow){
if(u==t)return flow;
int rest=flow;
for(int e=cur[u];e&&rest;e=nex[e]){
cur[u]=e;
int c=cap[e],v=ver[e];
if(c&&d[u]+1==d[v]){
int f=dinic(v,min(rest,c));
if(!f)d[v]=-1;
cap[e]-=f,cap[e^1]+=f,rest-=f;
}
}return flow-rest;
}
int calc(){
int flow=0;
for(;bfs();flow+=dinic(s,1e9));
return flow;
}
}
int n,m,id[60][60][2];
char mp[60][60];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
mf::s=++mf::n,mf::t=++mf::n;
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
if(mp[i][j]=='#'){
id[i][j][0]=++mf::n,id[i][j][1]=++mf::n;
mf::add(id[i][j][0],id[i][j][1],1);
}
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(mp[i][j]=='#'){
pair<int,int>adj[]{{i-1,j},{i+1,j},{i,j-1},{i,j+1},{i+1,j+1},{i-1,j+1},{i+1,j-1},{i-1,j-1}};
for(auto X:adj)if(mp[X.first][X.second]=='#'){
mf::add(id[i][j][1],id[X.first][X.second][0],1e9);
}
}
for(int i=1;i<=n;i++)mf::add(mf::s,id[i][1][0],1e9);
for(int i=1;i<=m;i++)mf::add(mf::s,id[n][i][0],1e9);
for(int i=1;i<=m;i++)mf::add(id[1][i][1],mf::t,1e9);
for(int i=1;i<=n;i++)mf::add(id[i][m][1],mf::t,1e9);
printf("%d",mf::calc());
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9956kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7948kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
7
result:
wrong answer 1st numbers differ - expected: '11', found: '7'