답안 #742776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742776 2023-05-16T22:55:54 Z ToniB Furniture (JOI20_furniture) C++17
0 / 100
2 ms 724 KB
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
typedef pair<int, int> pii;
const int MAXN = 1001;

int n, m, q, c[MAXN][MAXN], ans[MAXN * MAXN];
bool flag[MAXN][MAXN], bio[MAXN][MAXN], vis[MAXN][MAXN];
priority_queue<pair<pii, pii> > pq;

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			cin >> bio[i][j];
			c[i][j] = n * m + i * m + j;
		}
	}
	cin >> q;
	for(int i = 0; i < q; ++i){
		int x, y;
		cin >> x >> y, --x, --y;
		c[x][y] = i;
	}
	pq.push({{0, c[0][0]}, {0, 0}});
	bio[0][0] = 1;
	while(!pq.empty()){
		int x = pq.top().Y.X, y = pq.top().Y.Y;
		int val = pq.top().X.Y;
		pq.pop();
		if(x != n - 1 && !bio[x + 1][y]){
			bio[x + 1][y] = 1;
			pq.push({{x + y + 1, c[x + 1][y]}, {x + 1, y}});
			flag[x + 1][y] = 0;
		}
		if(y != m - 1 && !bio[x][y + 1]){
			bio[x][y + 1] = 1;
			pq.push({{x + y + 1, c[x][y + 1]}, {x, y + 1}});
			flag[x][y + 1] = 1;
		}
	}
	int i = n - 1, j = m - 1;
	while(i || j){
		if(flag[i][j]) --j;
		else --i;
		vis[i][j] = 1;
	}
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			if(c[i][j] < n * m) ans[c[i][j]] = vis[i][j];
		}
	}
	for(int i = 0; i < q; ++i){
		cout << !ans[i] << "\n";
	}
	return 0;
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:30:7: warning: unused variable 'val' [-Wunused-variable]
   30 |   int val = pq.top().X.Y;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -