Submission #1141161

#TimeUsernameProblemLanguageResultExecution timeMemory
1141161SmuggingSpunFurniture (JOI20_furniture)C++20
0 / 100
1 ms324 KiB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
int n, m;
namespace sub1{
	void solve(){
		vector<vector<bool>>c(n, vector<bool>(m, false));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				int x;
				cin >> x;
				if(x == 1){
					c[i][j] = true;
				}
			}
		}
		int q;
		cin >> q;
		for(int _ = 0; _ < q; _++){
			int x, y;
			cin >> x >> y;
			c[--x][--y] = true;
			vector<vector<bool>>vis(n, vector<bool>(m, false));
			auto dfs = [&] (auto&& self, int x, int y){
				if(x < 0 || x == n || y < 0 || y == m || vis[x][y] || c[x][y]){
					return;
				}
				vis[x][y] = true;
				self(self, x + 1, y);
				self(self, x, y + 1);
			};
			dfs(dfs, 0, 0);
			cout << vis[n - 1][m - 1] << "\n";
			if(!vis[n - 1][m - 1]){
				c[x][y] = false;
			}
		}
	}
}
namespace sub2{
	void solve(){
		vector<vector<bool>>c(n, vector<bool>(m, false));
		vector<int>cnt(n + m, 0);
		auto move = [&] (int i, int j){
			c[i][j] = true;
			cnt[i + j]--;
			queue<pair<int, int>>q;
			q.emplace(i - 1, j);
			q.emplace(i, j - 1);
			while(!q.empty()){
				auto [x, y] = q.front();
				q.pop();
				if(x == -1 || y == -1 || c[x][y]){
					continue;
				}
				if(!(x + 1 < n && !c[x + 1][y]) && !(y + 1 < m && !c[x][y + 1])){
					c[x][y] = true;
					cnt[x + y]--;
					q.emplace(x - 1, y);
					q.emplace(x, y - 1);
				}
			}			
		};
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				int x;
				cin >> x;
				cnt[i + j]++;
				if(x == 1){
					move(i, j);
				}
			}
		}
		int q;
		cin >> q;
		for(int _ = 0; _ < q; _++){
			int x, y;
			cin >> x >> y;
			if(c[--x][--y]){
				cout << "1\n";
				continue;
			}
			if(cnt[x + y] == 1){
				cout << "0\n";
				continue;
			}
			cout << "1\n";
			move(x, y);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n >> m;
	if(n <= 100 && m <= 100){
		sub2::solve();
	}
	else{
		sub2::solve();
	}
}

Compilation message (stderr)

furniture.cpp: In function 'int main()':
furniture.cpp:95:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...