Submission #553240

#TimeUsernameProblemLanguageResultExecution timeMemory
553240cheetoseFurniture (JOI20_furniture)C++17
100 / 100
392 ms8600 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...