Submission #1310469

#TimeUsernameProblemLanguageResultExecution timeMemory
1310469nanaseyuzukiFurniture (JOI20_furniture)C++20
0 / 100
2 ms1600 KiB
#include <bits/stdc++.h>
// Kazusa_Megumi
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;

#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif

const int mn = 3e3 + 5, mod = 1e9 + 7, inf = 2e9;

int m, n, a[mn][mn], in[mn][mn], out[mn][mn], cnt[mn << 1];

void del(int x, int y){
	if(a[x][y]) return;
	a[x][y] = 1;
	cnt[x + y] --;

	if(x > 1 && -- out[x - 1][y] == 0) del(x - 1, y);
	if(y > 1 && -- out[x][y - 1] == 0) del(x, y - 1);
	if(x < m && -- in[x + 1][y] == 0) del(x + 1, y);
	if(y < n && -- in[x][y + 1] == 0) del(x, y + 1); 
}

void solve() {
    cin >> m >> n;
    for(int i = 1; i <= m; i++){
    	for(int j = 1; j <= n; j++){
    		cin >> a[i][j];
    		in[i][j] = (i > 1) + (j > 1);
    		out[i][j] = (i < m) + (j < n);
    		cnt[i + j] ++;
    	}
    }

    for(int i = 1; i <= m; i++){
    	for(int j = 1; j <= n; j++){
    		if(a[i][j]){
    			a[i][j] = 0;
    			del(i, j);
    		}
    	}
    }
    int q; cin >> q;
    while(q--){
    	int x, y; cin >> x >> y;
    	if(cnt[x + y] > 1){
    		del(x, y);
    		cout << 1 << '\n';
    	}
    	else cout << a[x][y] << '\n';
    }
}

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    if (fopen("Kazuki.INP", "r")) {
        freopen("Kazuki.INP", "r", stdin);
        freopen("Kazuki.OUT", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Compilation message (stderr)

furniture.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main() {
      | ^~~~
furniture.cpp: In function 'int main()':
furniture.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen("Kazuki.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen("Kazuki.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...