Submission #791173

# Submission time Handle Problem Language Result Execution time Memory
791173 2023-07-23T13:46:53 Z Faee Furniture (JOI20_furniture) C++14
100 / 100
231 ms 25436 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
#define all(v) sort(v.begin(),v.end())
ll n,m,qq,x,y;
queue<pii> q;
ll grid[1010][1010],d[1000100];
bool vis[1010][1010];
vector<pii> v,vd;
bool cek;
void bfs() {
	cek = false;
	while(!q.empty()) {
		pii x = q.front();
		q.pop();
		d[x.fi+x.se]--;
		vd.pb({x.fi,x.se});
		if(d[x.fi+x.se] == 0) {
			cek = true;
			return;
		}
		if(vis[x.fi+1][x.se-1]) {
			if(!vis[x.fi+1][x.se]) {
				q.push({x.fi+1,x.se});
				vis[x.fi+1][x.se] = true;
				v.pb({x.fi+1,x.se});
			}
			if(!vis[x.fi][x.se-1]) {
				q.push({x.fi,x.se-1});			
				vis[x.fi][x.se-1] = true;			
				v.pb({x.fi,x.se-1});
			}
		}
		if(vis[x.fi-1][x.se+1]) {
			if(!vis[x.fi][x.se+1]) {
				q.push({x.fi,x.se+1});
				vis[x.fi][x.se+1] = true;
				v.pb({x.fi,x.se+1});
			}
			if(!vis[x.fi-1][x.se]) {
				q.push({x.fi-1,x.se});
				vis[x.fi-1][x.se] = true;				
				v.pb({x.fi-1,x.se});
			}
		} 
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	FOR(1,i,n) {
		FOR(1,j,m) {
			cin >> grid[i][j];
			vis[i][j] = grid[i][j];
			if(vis[i][j]) q.push({i,j});
			d[i+j]++;
		} 
	}
	FOR(1,i,m) vis[0][i] = true;
	FOR(1,i,n) vis[i][0] = true;
	FOR(1,i,m) vis[n+1][i] = true;
	FOR(1,i,n) vis[i][m+1] = true;
	bfs();
	v.clear();
	vd.clear();
	cin >> qq;
	while(qq--) {
		cin >> x >> y;
		if(vis[x][y]) {
			cout << 1 << endl;
			continue;
		}
		vis[x][y] = true;
		q.push({x,y});
		v.pb({x,y});
		bfs();
		if(cek) {
			cout << 0 << endl;
			for(auto i : vd) d[i.fi+i.se]++;
			for(auto i : v) vis[i.fi][i.se] = false;
		}
		else {
			cout << 1 << endl;
		}
		v.clear();
		vd.clear();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 8 ms 2756 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 110 ms 15548 KB Output is correct
13 Correct 52 ms 21400 KB Output is correct
14 Correct 194 ms 15020 KB Output is correct
15 Correct 221 ms 11072 KB Output is correct
16 Correct 206 ms 10592 KB Output is correct
17 Correct 209 ms 11112 KB Output is correct
18 Correct 215 ms 11148 KB Output is correct
19 Correct 222 ms 17568 KB Output is correct
20 Correct 231 ms 25436 KB Output is correct
21 Correct 220 ms 18212 KB Output is correct