Submission #1038389

#TimeUsernameProblemLanguageResultExecution timeMemory
1038389arashMLGFurniture (JOI20_furniture)C++17
100 / 100
203 ms12976 KiB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...)    69
#define debugArr(...)  69
#endif
using namespace std;

typedef long long     ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;

const int N = 1e3 + 23;
const ll inf = 1e18;

#define F           first
#define S           second
#define pb          push_back
#define kill(x)     cout<<x<<endl, exit(0);
#define all(x)      x.begin(),x.end()
#define sz(x)       (int)x.size()
#define lc          (v << 1)
#define rc          ((v<<1) |1)

int n,m;
bool ok[N][N];
int cnt[N*4];

bool check(int i,int j) {
	if(!ok[i][j]) return false;
	if((i == n && j == m) || (i == 1 && j == 1)) return false;
	if((!ok[i-1][j] && !ok[i][j-1]) || (!ok[i+1][j]	 && !ok[i][j+1])) {
		debug(i,j,!ok[i-1][j],!ok[i][j-1],!ok[i+1][j],!ok[i][j+1]);
		return true;
	} else {
		return false;
	}
}

int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};

void dfs(int x,int y) {
	ok[x][y] = 0;
	debug(x,y);
	cnt[x+y] --;
	for(int id= 0 ; id <4; id ++) {
		int x2 = x + dx[id],y2 = y + dy[id];
		if(check(x2,y2)) {
			dfs(x2,y2);
		}
	}
}

bool qry(int x,int y) {
	debug(x,y,ok[x][y]);
	if(!ok[x][y]) return true;
	if(cnt[x+y] == 1) return false;
	for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
	dfs(x,y);
	for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
	return true;
}

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin>>n>>m;
    for(int i =1; i <= n; i++) for(int j = 1; j <= m ; j ++) {
    	ok[i][j] = 1;
    	cnt[i+j] ++;
    }
    for(int i = 1;i <= n ;i ++) for(int j = 1; j<= m ; j ++) {
    	int x; cin>>x;
    	if(x) {
    		qry(i,j);
    	}
    }
    int q; cin>>q;
    while(q--) {
    	int x,y; cin>>x>>y;
    	cout<<qry(x,y) << '\n';
    }
	return 0;
}

// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!

Compilation message (stderr)

furniture.cpp: In function 'bool check(int, int)':
furniture.cpp:5:23: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...)    69
      |                       ^~
furniture.cpp:34:3: note: in expansion of macro 'debug'
   34 |   debug(i,j,!ok[i-1][j],!ok[i][j-1],!ok[i+1][j],!ok[i][j+1]);
      |   ^~~~~
furniture.cpp: In function 'void dfs(int, int)':
furniture.cpp:5:23: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...)    69
      |                       ^~
furniture.cpp:45:2: note: in expansion of macro 'debug'
   45 |  debug(x,y);
      |  ^~~~~
furniture.cpp: In function 'bool qry(int, int)':
furniture.cpp:5:23: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...)    69
      |                       ^~
furniture.cpp:56:2: note: in expansion of macro 'debug'
   56 |  debug(x,y,ok[x][y]);
      |  ^~~~~
furniture.cpp:6:24: warning: statement has no effect [-Wunused-value]
    6 | #define debugArr(...)  69
      |                        ^~
furniture.cpp:59:32: note: in expansion of macro 'debugArr'
   59 |  for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
      |                                ^~~~~~~~
furniture.cpp:6:24: warning: statement has no effect [-Wunused-value]
    6 | #define debugArr(...)  69
      |                        ^~
furniture.cpp:61:32: note: in expansion of macro 'debugArr'
   61 |  for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
      |                                ^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...