답안 #936345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936345 2024-03-01T16:28:22 Z OAleksa Furniture (JOI20_furniture) C++14
0 / 100
1 ms 7256 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 1069;
int n, m, a[N][N], dp1[N][N], dp2[N][N];
int g[N][N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	cin >> n >> m;
  	for (int i = 1;i <= n;i++) {
  		for (int j = 1;j <= m;j++)
  			cin >> a[i][j];
  	}
  	for (int i = 1;i <= n;i++) {
  		for (int j = 1;j <= m;j++) 
  			dp1[i][j] = (dp1[i - 1][j] | dp1[i][j - 1] | a[i][j]);
  	}
  	for (int i = n;i >= 0;i--) {
  		for (int j = m;j >= 0;j--)
  			dp2[i][j] = (dp2[i + 1][j] | dp2[i][j + 1] | a[i][j]);
  	}
  	for (int i = 1;i <= n;i++) {
  		for (int j = 1;j <= m;j++)
  			g[i][j] = (dp1[i][j] | dp2[i][j]);
  	}
  	for (int i = 1;i <= m;i++) 
  		g[0][i] = g[n + 1][i] = 1;
  	for (int i = 1;i <= n;i++)
  		g[i][0] = g[i][m + 1] = 1;
  	g[1][1] = g[n][m] = 0;
  	int q;
  	cin >> q;
  	while (q--) {
  		int x, y;
  		cin >> x >> y;
  		int ok = 0;
  		queue<pair<int, int>> q;
			q.push({x, y});
			while (!q.empty()) {
				auto v = q.front();
				int i = v.f, j = v.s;
				g[i][j] = 1;
				q.pop();
				if (i > 0 && g[i - 1][j + 1] && !g[i - 1][j])
					q.push({i - 1, j});
				if (j > 0 && g[i + 1][j - 1] && !g[i][j - 1])
					q.push({i, j - 1});
			}
			q.push({x, y});
			while (!q.empty()) {
				auto v = q.front();
				int i = v.f, j = v.s;
				g[i][j] = 1;
				q.pop();
				if (i > 0 && g[i - 1][j + 1] && !g[i][j + 1])
					q.push({i, j + 1});
				if (j > 0 && g[i + 1][j - 1] && !g[i + 1][j])
					q.push({i + 1, j});
			}
  		if (!g[1][2] || !g[2][1]) 
  			cout << 1 << '\n';
  		else {
  			q.push({x, y});
				while (!q.empty()) {
					auto v = q.front();
					int i = v.f, j = v.s;
					g[i][j] = 0;
					q.pop();
					if (i > 0 && g[i - 1][j + 1] && g[i - 1][j])
						q.push({i - 1, j});
					if (j > 0 && g[i + 1][j - 1] && g[i][j - 1])
						q.push({i, j - 1});
				}
				q.push({x, y});
				while (!q.empty()) {
					auto v = q.front();
					int i = v.f, j = v.s;
					g[i][j] = 0;
					q.pop();
					if (i > 0 && g[i - 1][j + 1] && g[i][j + 1])
						q.push({i, j + 1});
					if (j > 0 && g[i + 1][j - 1] && g[i + 1][j])
						q.push({i + 1, j});
				}
  			cout << 0 << '\n';
  		}
  	}
  }
  return 0;
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:42:9: warning: unused variable 'ok' [-Wunused-variable]
   42 |     int ok = 0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 7256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 7256 KB Output isn't correct
2 Halted 0 ms 0 KB -