能过样例,但对拍总是比答案小一点或是大一点,求调
查看原帖
能过样例,但对拍总是比答案小一点或是大一点,求调
508530
P7GAB楼主2024/10/21 17:55
#include<bits/stdc++.h>
#define syt cerr<<"sytakioi"<<endl;
#define int long long
#define sca cerr<<"scaakioi"<<endl;
using namespace std;
const int maxn=3e3+10;
const int inf=0x3f3f3f3f;
int lf[maxn][maxn];
int mp[maxn][maxn];
int n,m,q,r,k;
int dx[4]= {-1,1,0,0};
int dy[4]= {0,0,-1,1};
bool check(int x,int y,int t) {
	return mp[x][y]==inf or x<1 or x>n or y<1 or y>m or (mp[x][y]<t && lf[x][y]>=t);
}
bool check2(int x,int y) {
	return mp[x][y]==inf or x<1 or x>n or y<1 or y>m;
}
bool vis[maxn][maxn];
void dfs(int t,int x,int y) {
	//if(mp[x][y]<t && lf[x][y]>=t)
	//	return;
	for(int i=0; i<4; i++) {
		int tx=x+dx[i],ty=y+dy[i];
		bool flag=0;
		for(int j=0; j<4; j++)
			if(mp[tx+dx[j]][ty+dy[j]]==inf)
				flag=1;
		if(!check(tx,ty,t+1) && flag) {
			lf[x][y]=inf<<1,mp[tx][ty]=t+1,dfs(t+1,tx,ty);
			//cout<<"("<<tx<<","<<ty<<")"<<endl;
		}
	}
}
//bool vis[maxn][maxn];
signed main() {
	//freopen("lake.in","r",stdin);
//	freopen("lake.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q>>r>>k;
	while(q--) {
		int a,b,x,y;
		cin>>a>>b>>x>>y;
		for(int i=a; i<=x; i++)
			for(int j=b; j<=y; j++)
				mp[i][j]=inf;
	}
	for(int i=0; i<=m+1; i++)
		mp[0][i]=inf+1,mp[n+1][i]=inf+1;
	for(int i=0; i<=n+1; i++)
		mp[i][0]=inf+1,mp[i][m+1]=inf+1;
	//syt
	while(r--) {
		int t,x,y;
		cin>>t>>x>>y;
		if((mp[x][y]<t && lf[x][y]>=t) or mp[x][y]==inf or lf[x][y]==inf<<1)
			continue;
		mp[x][y]=t;
		lf[x][y]=t+k;
		dfs(t,x,y);
		//syt
	}

	int ans=0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(mp[i][j]!=0 && lf[i][j]==inf<<1) {
				ans++;
				vis[i][j]=1;
			} else {
				int ss=0,kl=0;
				if(mp[i][j]!=0 && mp[i][j]!=inf && lf[i][j]!=inf<<1) {
					for(int k=0; k<4; k++) {
						int tx=i+dx[k],ty=j+dy[k];
						if(mp[tx][ty]==inf or mp[tx][ty]==inf+1)
							ss++;
						if(!vis[tx][ty] && !check2(tx,ty) && (lf[tx][ty]==inf<<1 or (max(mp[i][j],mp[tx][ty])<=min(lf[tx][ty],lf[i][j])))) {
//							cout<<"("<<i<<","<<j<<")"<<endl;
							kl=1;
//							cout<<"("<<tx<<","<<ty<<")"<<endl;
							vis[tx][ty]=1;
							ans++;

						}
					}
					if(ss==4 or kl==1)
						ans++;
					//cout<<lf[i][j]<<endl;
					vis[i][j]=1;
				}

			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

2024/10/21 17:55
加载中...