Submission #496068

# Submission time Handle Problem Language Result Execution time Memory
496068 2021-12-20T13:53:26 Z minhcool Furniture (JOI20_furniture) C++17
5 / 100
2644 ms 884 KB
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 105;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, m, c[N][N], q;
 
bool vis[N][N];
 
bool ck(){
	stack<ii> bfs;
  	while(!bfs.empty()) bfs.pop();
	bfs.push({1, 1});
    for(int i = 1; i <= n; i++){
  		for(int j = 1; j <= m; j++) vis[i][j] = 0;
  	}
    vis[1][1] = 1;
  int cnt = 0;
	while(!bfs.empty()){
		ii u = bfs.top();
		bfs.pop();
      cnt++;
      assert(cnt <= n * m);
        vis[u.fi][u.se] = 1;
		if(u == make_pair(n, m)) return 1;
		if(u.se < m && c[u.fi][u.se + 1] == 0 && !vis[u.fi][u.se + 1]) bfs.push({u.fi, u.se + 1});
		if(u.fi < n && c[u.fi + 1][u.se] == 0 && !vis[u.fi + 1][u.se]) bfs.push({u.fi + 1, u.se});
	}
	return 0;
}
 
void process(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++) cin >> c[i][j];
	}
	cin >> q;
	while(q--){
		int x, y;
		cin >> x >> y;
		c[x][y] = 1;
		if(!ck()){
			cout << 0 << "\n";
			c[x][y] = 0;
		}
		else cout << 1 << "\n";
	}
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	process();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 19 ms 324 KB Output is correct
3 Correct 45 ms 424 KB Output is correct
4 Correct 90 ms 460 KB Output is correct
5 Correct 77 ms 464 KB Output is correct
6 Correct 99 ms 500 KB Output is correct
7 Correct 109 ms 488 KB Output is correct
8 Correct 88 ms 460 KB Output is correct
9 Correct 589 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 19 ms 324 KB Output is correct
3 Correct 45 ms 424 KB Output is correct
4 Correct 90 ms 460 KB Output is correct
5 Correct 77 ms 464 KB Output is correct
6 Correct 99 ms 500 KB Output is correct
7 Correct 109 ms 488 KB Output is correct
8 Correct 88 ms 460 KB Output is correct
9 Correct 589 ms 592 KB Output is correct
10 Incorrect 2644 ms 884 KB Output isn't correct
11 Halted 0 ms 0 KB -