Submission #891592

# Submission time Handle Problem Language Result Execution time Memory
891592 2023-12-23T10:01:48 Z amirhoseinfar1385 Furniture (JOI20_furniture) C++17
0 / 100
3 ms 11356 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn=1000+10;
int dpb[maxn][maxn],dpp[maxn][maxn],dp[maxn][maxn],all[maxn][maxn],n,m;
set<pair<int,int>>st[maxn*3];

void updb(int i,int j){
	if(dpb[i][j]==0){
		return ;
	}
	dpb[i][j]=(dpb[i-1][j]|dpb[i][j-1]);
	if(dpb[i][j]==0){
		st[i+j].erase(make_pair(i,j));
		updb(i+1,j);
		updb(i,j+1);
	}
}

void updp(int i,int j){
	if(dpp[i][j]==0){
		return ;
	}
	dpp[i][j]=(dpp[i+1][j],dpp[i][j+1]);
	if(dpp[i][j]==0){
		st[i+j].erase(make_pair(i,j));
		updp(i+1,j);
		updp(i,j+1);
	}
}

void query(){
	int i,j;
	cin>>i>>j;
	if((int)st[i+j].size()!=1||st[i+j].count(make_pair(i,j))==0){
		cout<<1<<"\n";
		dp[i][j]=dpb[i][j]=dpp[i][j]=0;
		updb(i,j+1);
		updb(i+1,j);
		updp(i,j-1);
		updp(i-1,j);
		st[i+j].erase(make_pair(i,j));
	}
	else{
		cout<<0<<"\n";
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>all[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(all[i][j]){
				continue;
			}
			if(i==1&&j==1){
				dpb[i][j]=1;
				continue;
			}
			if((dpb[i-1][j]|dpb[i][j-1])==1){
				dpb[i][j]=1;
			}
		}
	}
	for(int i=n;i>=1;i--){
		for(int j=m;j>=1;j--){
			if(i==n&&j==m){
				dpp[i][j]=1;
				continue;
			}
			if(all[i][j]){
				continue;
			}
			if((dpp[i+1][j]|dpp[i][j+1])==1){
				dpp[i][j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=(dpp[i][j]&dpb[i][j]);
			if(dp[i][j]){
				st[i+j].insert(make_pair(i,j));
			}
		}
	}
	int q;
	cin>>q;
	for(int asd=0;asd<q;asd++){
		query();
	}
}

Compilation message

furniture.cpp: In function 'void updp(int, int)':
furniture.cpp:23:23: warning: left operand of comma operator has no effect [-Wunused-value]
   23 |  dpp[i][j]=(dpp[i+1][j],dpp[i][j+1]);
      |             ~~~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11356 KB Output is correct
2 Incorrect 3 ms 11100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11356 KB Output is correct
2 Incorrect 3 ms 11100 KB Output isn't correct
3 Halted 0 ms 0 KB -