Submission #599442

# Submission time Handle Problem Language Result Execution time Memory
599442 2022-07-19T14:11:29 Z jmyszka2007 Furniture (JOI20_furniture) C++17
0 / 100
3 ms 960 KB
#include <bits/stdc++.h>
using namespace std;
bool to[1010][1010];
bool from[1010][1010];
int cnt[2010];
int meb[1010][1010];
bool czy[1010][1010];
int n, m;
void dfst(int x, int y) {
	if(x > n || y > m) {
		return;
	}
	to[x][y] = 0;
	if(!to[x - 1][y + 1] && to[x + 1][y])  {
		dfst(x + 1, y);
	}
	if(!to[x + 1][y - 1] && to[x][y + 1]) {
		dfst(x, y + 1);
	}
	if(czy[x][y]) {
		cnt[x + y]--;
		czy[x][y] = 0;
	}
}
void dfsf(int x, int y) {
	if(x < 1 || y < 1) {
		return;
	}
	from[x][y] = 0;
	if(!from[x - 1][y + 1] && from[x - 1][y]) {
		dfsf(x - 1, y);
	}
	if(!from[x + 1][y - 1] && from[x][y - 1]) {
		dfsf(x, y - 1);
	}
	if(czy[x][y]) {
		cnt[x + y]--;
		czy[x][y] = 0;
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			scanf("%d", &meb[i][j]);
		}
	}
	to[1][1] = 1;
	from[n][m] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(!meb[i][j]) {
				if(to[i - 1][j] || to[i][j - 1]) {
					to[i][j] = 1;
				}
			}
		}
	}
	for(int i = n; i >= 1; i--) {
		for(int j = m; j >= 1; j--) {
			if(!meb[i][j]) {
				if(from[i + 1][j] || from[i][j + 1]) {
					from[i][j] = 1;
				}
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(to[i][j] && from[i][j]) {
				cnt[i + j]++;
				czy[i][j] = 1;
			}
		}
	}
	int t;
	scanf("%d", &t);
	while(t--) {
		int a, b;
		scanf("%d%d", &a, &b);
		if(cnt[a + b] > 1 || !to[a][b] || !from[a][b]) {
			//cout << cnt[a + b]  << ' ' << to[a][b] << ' ' << from[a][b] << '\n';
			printf("%d\n", 1);
			meb[a][b] = 1;
			if(to[a][b]) {
				dfst(a, b);
			}
			if(from[a][b]) {
				dfsf(a, b);
			}
		}
		else {
			printf("%d\n", 0);
		}
	}
}
 

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
furniture.cpp:45:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |    scanf("%d", &meb[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~
furniture.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
furniture.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Incorrect 3 ms 960 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Incorrect 3 ms 960 KB Output isn't correct
3 Halted 0 ms 0 KB -