萌新刚学OI简单模拟WA#6求调
查看原帖
萌新刚学OI简单模拟WA#6求调
556545
_anll_楼主2024/7/8 17:08

rt,最初用 map 维护重复是 TLE#12,改成 vector 打标记维护后就变成 WA#6 了,改了很多种清空没解决问题,本蒟蒻也看不出来哪里写假了,跪求 dalao 们帮忙QAQ。 原 map 代码:

void check2(){
	int xx,yy,tot1=0,tot2=0;
	if(x<1||x>n||y<1||y>m) return;
	mo.clear();
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(mo[{xx,yy}]) continue;//
		mo[{xx,yy}]=1;
		if(!check1(xx,yy)) tot1++;
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(mo[{xx,yy}]) continue;//
		mo[{xx,yy}]=1;
		if(!check1(xx,yy)) tot1++;
	}
	mo.clear();
	swap(mp[a][b],mp[x][y]);
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(mo[{xx,yy}]) continue;//
		mo[{xx,yy}]=1;
		if(!check1(xx,yy)) tot2++;
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(mo[{xx,yy}]) continue;//
		mo[{xx,yy}]=1;
		if(!check1(xx,yy)) tot2++;
	}
	if(cnt-(tot1-tot2)==0&&!vu[{{a,b},{x,y}}]){
		vu[{{a,b},{x,y}}]=vu[{{x,y},{a,b}}]=1;
		ans++;
	}
	swap(mp[a][b],mp[x][y]);
}

现 vector 代码:

void check2(int a,int b,int x,int y){
	int xx,yy,tot1=0,tot2=0;
	if(!ch(x,y)) return;
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;//
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot1++;
		
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;//
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot1++;
	}
	for(int i=0;i<5;i++){//清空
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
	}
	swap(mp[a][b],mp[x][y]);
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;//
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot2++;
		
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;//
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot2++;
	}
	if(cnt-(tot1-tot2)==0&&!vu[{{a,b},{x,y}}]){
		vu[{{a,b},{x,y}}]=vu[{{x,y},{a,b}}]=1;
		ans++;
	}
	swap(mp[a][b],mp[x][y]);
	for(int i=0;i<5;i++){//清空
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
	}
}

完整 WA 代码:

#include<unordered_map>
#include<iostream>
#include<vector>
#include<map>
#define C 5201413
#define int long long
using namespace std;
const int N=4e5+5;
int n,m,cnt,tot,ans,px,py,pos[5][2]={{+1,0},{-1,0},{0,+1},{0,-1},{0,0}};
vector<int> mp[N],vo[N];
map<pair<pair<int,int>,pair<int,int> >,int> vu;
bool ch(int x,int y){
	if(x<1||x>n||y<1||y>m) return 0;
	return 1;
}
bool check1(int x,int y){
	for(int i=0;i<4;i++){
		int xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)) continue;
		if(mp[xx][yy]<mp[x][y]) return 1;
	}
	return 0;
}
void check2(int a,int b,int x,int y){
	int xx,yy,tot1=0,tot2=0;
	if(!ch(x,y)) return;
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot1++;
		
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot1++;
	}
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
	}
	swap(mp[a][b],mp[x][y]);
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot2++;
		
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)||vo[xx][yy]) continue;
		vo[xx][yy]=1;
		if(!check1(xx,yy)) tot2++;
	}
	if(cnt-(tot1-tot2)==0&&!vu[{{a,b},{x,y}}]){
		vu[{{a,b},{x,y}}]=vu[{{x,y},{a,b}}]=1;
		ans++;
	}
	swap(mp[a][b],mp[x][y]);
	for(int i=0;i<5;i++){
		xx=x+pos[i][0],yy=y+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
		xx=a+pos[i][0],yy=b+pos[i][1];
		if(!ch(xx,yy)) continue;
		vo[xx][yy]=0;
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;int awa;
	for(int i=1;i<=n;i++){
		mp[i].push_back(0);vo[i].push_back(0);
		for(int j=1;j<=m;j++){
			cin>>awa;
			mp[i].push_back(awa);vo[i].push_back(0);
		}
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
		if(!check1(i,j)&&mp[i][j]!=1) cnt++,px=i,py=j;
	if(!cnt){cout<<0;return 0;}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=0;k<5;k++){
				check2(i,j,px+pos[k][0],py+pos[k][1]);
			}
		}
	}
	if(ans) cout<<"1 "<<ans;
	else cout<<2;
	return 0;
}
2024/7/8 17:08
加载中...