답안 #534726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534726 2022-03-08T16:32:10 Z michao Furniture (JOI20_furniture) C++14
0 / 100
14 ms 17356 KB
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1e3+5;
int a[MAX][MAX];
int dp[MAX][MAX]; // czy istnieje sciezka przechodzaca przez punkt, 0 jesli tak 1 jesli nie
int n,m;
int ile[MAX+MAX];
bool check(int x,int y){
	if (ile[x+y]==1 && dp[x][y]==0)return false;
	return true;
}

void zaznacz(int x,int y){
  assert(check(x,y));
	a[x][y]=1;
	dp[x][y]=1;
	ile[x+y]--;
}

bool check2(int x,int y){
	return x>=1 && x<=n && y>=1 && y<=m;
}

bool blocked(int x,int y){
	if (dp[x][y]==1)return false;
	if (dp[x-1][y]==1 && dp[x][y-1]==1 && (x>1 || y>1))return true;
	if (dp[x+1][y]==1 && dp[x][y+1]==1 && (x<n || y<m))return true;
	return false;
}

int px[4]={1,-1,0,0};
int py[4]={0,0,-1,1};
void block(int x,int y){
	assert(check(x,y));
	queue<pii>q;
	zaznacz(x,y);
	q.push(mp(x,y));
	while (!q.empty()){
		x=q.front().st;
		y=q.front().nd;
		for (int i=0;i<4;i++){
			int tox=x+px[i];
			int toy=y+py[i];
			if (!check2(tox,toy))continue;
			if (blocked(tox,toy)){
				zaznacz(tox,toy);
				q.push(mp(tox,toy));
			}
		}
		q.pop();
	}
}
int32_t main(){
  BOOST;
  cin>>n>>m;
  for (int i=0;i<=MAX-1;i++)for (int j=0;j<=MAX-1;j++){
		dp[i][j]=1;
  }
  
  for (int i=1;i<=n;i++)for (int j=1;j<=m;j++)dp[i][j]=0,ile[i+j]++;
  for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			cin>>a[i][j];
		}
  }
  
  for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			if (a[i][j]==1){
				block(i,j);
			}
		}
  }
  int t;
  cin>>t;
  for (int z=0;z<t;z++){
		int x,y;
		cin>>x>>y;
		if (check(x,y)){
			block(x,y);
			cout<<"1\n";
		}
		else cout<<"0\n";
  }
  return 0; 
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Runtime error 14 ms 17356 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Runtime error 14 ms 17356 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -