Submission #1154048

#TimeUsernameProblemLanguageResultExecution timeMemory
1154048minggaFurniture (JOI20_furniture)C++20
100 / 100
157 ms7408 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
// #define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 1e3 + 7;
int n, m, a[N][N], q;
int cross[N * 5];
bool f[N][N];


vector<pair<int, int>> st;

void add(int x, int y) {
	if(f[x][y]) return;
	f[x][y] = 1;
	cross[x + y]--;
	st.push_back({x, y});
}

bool check(int x, int y) {
	if(f[x][y]) return 1;
	if(cross[x + y] == 1) return 0;
	add(x, y);
	while(sz(st)) {
		int a = st.back().fi, b = st.back().se;
		st.pop_back();
		if(f[a - 1][b + 1]) {
			add(a - 1, b);
			add(a, b + 1);
		}
		if(f[a + 1][b - 1]) {
			add(a, b - 1);
			add(a + 1, b);
		}
	}
	return 1;
}


signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cross[i + j]++;
		}
	}
	for(int i = 1; i <= n; i++) f[i][0] = f[i][m + 1] = 1;
	for(int i = 1; i <= m; i++) f[0][i] = f[n + 1][i] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> a[i][j];
			if(a[i][j]) check(i, j);
		}
	}
	cin >> q;
	for(int i = 1; i <= q; i++) {
		int x, y; cin >> x >> y;
		cout << check(x, y) << ln;
	}
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

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