QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533684#9224. Express Evictionucup-team1004WA 1ms4384kbC++142.7kb2024-08-26 10:30:562024-08-26 10:30:58

Judging History

你现在查看的是最新测评结果

  • [2024-08-26 10:30:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4384kb
  • [2024-08-26 10:30:56]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=50+5,M=N*N*10+5,K=1e7+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,k;char c[N];

struct yyy{int to,w,z;};struct ljb{int head=1,h[M];yyy f[M];void add(int x,int y,int z){f[++head]=(yyy){y,z,h[x]};h[x]=head;}}s;
void con(int x,int y,int z){s.add(x,y,z);s.add(y,x,0);}
int S,T;
namespace Dicnic{
	int d[M],Ns[M];
	int bfs(){
		queue<int> q;Me(d,0x3f);Mc(Ns,s.h);d[S]=0;q.push(S);
		while(!q.empty()){
			int x=q.front();q.pop();yyy tmp;
			for(int i=s.h[x];i;i=tmp.z){
				tmp=s.f[i];if(tmp.w&&d[tmp.to]>d[x]+1) q.push(tmp.to),d[tmp.to]=d[x]+1;
			}
		}
		return d[T]<INF;
	}
	int dfs(int x,int Sum){
		if(x==T) return Sum;yyy tmp;int k,pus=0;
		for(int &i=Ns[x];i;i=tmp.z){
			tmp=s.f[i];if(!tmp.w||d[tmp.to]!=d[x]+1) continue;k=dfs(tmp.to,min(tmp.w,Sum));
			if(!k) d[tmp.to]=INF;s.f[i].w-=k;s.f[i^1].w+=k;pus+=k;Sum-=k;if(!Sum) break;
		}
		return pus;
	}
	int calc(){int ans=0;while(bfs()) ans+=dfs(S,INF);return ans;}
}
int getid(int x,int y){return (x-1)*m+y;}
void Solve(){
	scanf("%d%d",&n,&m);
	S=0,T=n*m*3+1;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) con(S,getid(i,j),n*m*4),con(getid(i,j),T,n*m*4);
	int cnt=0;
	for(int i=1;i<=n;i++){
		scanf("%s",c+1);
		for(int j=1;j<=m;j++)if(c[j]=='#'){
			cnt++;
			con(S,getid(i,j)+n*m,1);con(getid(i,j)+n*m*2,T,1);
			con(getid(i,j)+n*m,getid(i,j),1);con(getid(i,j),getid(i,j)+n*m*2,1);
			for(int ox:{1,-1}) for(int oy:{1,-1}){
				int x=i+(ox+oy)/2,y=j+(ox-oy)/2;
				int id=getid(x,y);
				if(y<1||x>n) id=T;
				if(x<1||y>m) id=S;
				if(id^S) con(getid(i,j)+n*m,id,1);
				if(id^T) con(id,getid(i,j)+n*m*2,1);
				gdb(i,j,x,y);
			}
		}
	}
	printf("%d\n",Dicnic::calc()-n*m*4*n*m-cnt);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4212kb

input:

4 6
.##...
.#....
##....
....#.

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 4384kb

input:

20 30
...###########################
#..###########################
...###########################
...###########################
.#############################
...###########################
...###########################
#..###########################
...###########################
..#...............

output:

7

result:

wrong answer 1st numbers differ - expected: '11', found: '7'