Submission #553240

# Submission time Handle Problem Language Result Execution time Memory
553240 2022-04-25T07:23:47 Z cheetose Furniture (JOI20_furniture) C++17
100 / 100
392 ms 8600 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int a[1005][1005];
int cnt[2010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	fup(i,1,n,1)fup(j,1,m,1)scanf("%d",a[i]+j);
	fup(i,1,m,1)a[0][i]=a[n+1][i]=1;
	fup(i,1,n,1)a[i][0]=a[i][m+1]=1;
	fup(i,1,n,1){
		fup(j,1,m,1){
			if(i+j==n+m || i+j==2)continue;
			if(a[i-1][j] && a[i][j-1])a[i][j]=1;
		}
	}
	fdn(i,n,1,1){
		fdn(j,m,1,1){
			if(i+j==n+m || i+j==2)continue;
			if(a[i+1][j] && a[i][j+1])a[i][j]=1;
		}
	}
	fup(i,1,n,1){
		fup(j,1,m,1){
			if(!a[i][j])cnt[i+j]++;
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		if(a[x][y]){
			puts("1");
		}else if(cnt[x+y]==1)puts("0");
		else{
			puts("1");
			a[x][y]=1;
			cnt[x+y]--;
			queue<Pi> q;
			q.push(mp(x,y));
			while(!q.empty()){
				auto [xx,yy]=q.front();
				q.pop();
				fup(k,0,1,1){
					int nx=xx+dx[k],ny=yy+dy[k];
					if(nx>=1 && nx<=n && ny>=1 && ny<=m && !a[nx][ny] && a[nx-1][ny] && a[nx][ny-1]){
						q.push(mp(nx,ny));
						a[nx][ny]=1;
						cnt[nx+ny]--;
					}
				}
			}
			q.push(mp(x,y));
			while(!q.empty()){
				auto [xx,yy]=q.front();
				q.pop();
				fup(k,2,3,1){
					int nx=xx+dx[k],ny=yy+dy[k];
					if(nx>=1 && nx<=n && ny>=1 && ny<=m && !a[nx][ny] && a[nx+1][ny] && a[nx][ny+1]){
						q.push(mp(nx,ny));
						a[nx][ny]=1;
						cnt[nx+ny]--;
					}
				}
			}
		}
	}
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:48:2: note: in expansion of macro 'fup'
   48 |  fup(i,1,n,1)fup(j,1,m,1)scanf("%d",a[i]+j);
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:48:14: note: in expansion of macro 'fup'
   48 |  fup(i,1,n,1)fup(j,1,m,1)scanf("%d",a[i]+j);
      |              ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:49:2: note: in expansion of macro 'fup'
   49 |  fup(i,1,m,1)a[0][i]=a[n+1][i]=1;
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:50:2: note: in expansion of macro 'fup'
   50 |  fup(i,1,n,1)a[i][0]=a[i][m+1]=1;
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:51:2: note: in expansion of macro 'fup'
   51 |  fup(i,1,n,1){
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:52:3: note: in expansion of macro 'fup'
   52 |   fup(j,1,m,1){
      |   ^~~
furniture.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
furniture.cpp:57:2: note: in expansion of macro 'fdn'
   57 |  fdn(i,n,1,1){
      |  ^~~
furniture.cpp:11:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
furniture.cpp:58:3: note: in expansion of macro 'fdn'
   58 |   fdn(j,m,1,1){
      |   ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:63:2: note: in expansion of macro 'fup'
   63 |  fup(i,1,n,1){
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:64:3: note: in expansion of macro 'fup'
   64 |   fup(j,1,m,1){
      |   ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:85:5: note: in expansion of macro 'fup'
   85 |     fup(k,0,1,1){
      |     ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:98:5: note: in expansion of macro 'fup'
   98 |     fup(k,2,3,1){
      |     ^~~
furniture.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
furniture.cpp:48:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  fup(i,1,n,1)fup(j,1,m,1)scanf("%d",a[i]+j);
      |                          ~~~~~^~~~~~~~~~~~~
furniture.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
furniture.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 704 KB Output is correct
4 Correct 3 ms 712 KB Output is correct
5 Correct 3 ms 704 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 764 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 704 KB Output is correct
4 Correct 3 ms 712 KB Output is correct
5 Correct 3 ms 704 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 764 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 15 ms 864 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 207 ms 7104 KB Output is correct
13 Correct 66 ms 5772 KB Output is correct
14 Correct 251 ms 7912 KB Output is correct
15 Correct 303 ms 8140 KB Output is correct
16 Correct 360 ms 8332 KB Output is correct
17 Correct 293 ms 8536 KB Output is correct
18 Correct 296 ms 8428 KB Output is correct
19 Correct 307 ms 8600 KB Output is correct
20 Correct 295 ms 8568 KB Output is correct
21 Correct 392 ms 8576 KB Output is correct