Submission #918754

# Submission time Handle Problem Language Result Execution time Memory
918754 2024-01-30T11:35:51 Z waldi Furniture (JOI20_furniture) C++17
100 / 100
241 ms 15960 KB
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) (int(x.size()))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	vector czy(n, vector(m, 1));
	vector suma(n+m-1, 0);
	REP(i, n) REP(j, m) ++suma[i+j];
	
	auto usun = [&](int si, int sj){
		if(!czy[si][sj]) return;
		czy[si][sj] = 0;
		--suma[si+sj];
		
		queue<pii> q;
		q.emplace(si+1, sj);
		q.emplace(si, sj+1);
		while(ssize(q)){
			auto [i, j] = q.front(); q.pop();
			if(i<0 || j<0 || i>=n || j>=m || !czy[i][j]) continue;
			if(i && czy[i-1][j]) continue;
			if(j && czy[i][j-1]) continue;
			czy[i][j] = 0;
			--suma[i+j];
			q.emplace(i+1, j);
			q.emplace(i, j+1);
		}
		
		q.emplace(si-1, sj);
		q.emplace(si, sj-1);
		while(ssize(q)){
			auto [i, j] = q.front(); q.pop();
			if(i<0 || j<0 || i>=n || j>=m || !czy[i][j]) continue;
			if(i+1<n && czy[i+1][j]) continue;
			if(j+1<m && czy[i][j+1]) continue;
			czy[i][j] = 0;
			--suma[i+j];
			q.emplace(i-1, j);
			q.emplace(i, j-1);
		}
	};
	
	auto niemoge = [&](int i, int j){
		if(!czy[i][j]) return false;
		return suma[i+j] == 1;
	};
	
	REP(i, n) REP(j, m){
		int a;
		scanf("%d", &a);
		if(a) usun(i, j);
	}
	
	int q;
	scanf("%d", &q);
	while(q--){
		int i, j;
		scanf("%d%d", &i, &j);
		--i, --j;
		if(niemoge(i, j)) printf("0\n");
		else usun(i, j), printf("1\n");
	}
	return 0;
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
furniture.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%d", &a);
      |   ~~~~~^~~~~~~~~~
furniture.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
furniture.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d%d", &i, &j);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 540 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 540 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 9 ms 856 KB Output is correct
11 Correct 2 ms 536 KB Output is correct
12 Correct 155 ms 8560 KB Output is correct
13 Correct 76 ms 5460 KB Output is correct
14 Correct 210 ms 13396 KB Output is correct
15 Correct 220 ms 13352 KB Output is correct
16 Correct 222 ms 14924 KB Output is correct
17 Correct 218 ms 15440 KB Output is correct
18 Correct 233 ms 14888 KB Output is correct
19 Correct 218 ms 15920 KB Output is correct
20 Correct 225 ms 15952 KB Output is correct
21 Correct 241 ms 15960 KB Output is correct