Submission #569782

#TimeUsernameProblemLanguageResultExecution timeMemory
569782mat_vFurniture (JOI20_furniture)C++14
100 / 100
335 ms17820 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n,m; int mat[1005][1005]; int kol[2005]; bool dobar[1005][1005][2]; void radi(int x, int y, int idx){ if(x <= 0 && y <= 0 && x > n || y > m)return; if(!dobar[x][y][idx])return; if(idx == 0){ bool sta = 0; if(!mat[x+1][y])sta |= dobar[x+1][y][0]; if(!mat[x][y+1])sta |= dobar[x][y+1][0]; if(!sta){ if(dobar[x][y][idx^1])kol[x+y]--; dobar[x][y][idx] = 0; radi(x-1,y,0); radi(x,y-1,0); } } else{ bool sta = 0; if(!mat[x-1][y])sta |= dobar[x-1][y][1]; if(!mat[x][y-1])sta |= dobar[x][y-1][1]; if(!sta){ if(dobar[x][y][idx^1])kol[x+y]--; dobar[x][y][idx] = 0; radi(x+1,y,1); radi(x,y+1,1); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; ff(i,1,n){ ff(j,1,m)cin >> mat[i][j]; } dobar[n][m][0] = 1; dobar[1][1][1] = 1; fb(i,n,1){ fb(j,m,1){ if(i == n && j == m || mat[i][j] == 1)continue; if(!mat[i+1][j])dobar[i][j][0] |= dobar[i+1][j][0]; if(!mat[i][j+1])dobar[i][j][0] |= dobar[i][j+1][0]; } } ff(i,1,n){ ff(j,1,m){ if(i == 1 && j == 1 || mat[i][j] == 1)continue; if(!mat[i-1][j])dobar[i][j][1] |= dobar[i-1][j][1]; if(!mat[i][j-1])dobar[i][j][1] |= dobar[i][j-1][1]; } } ff(i,1,n){ ff(j,1,m){ if(dobar[i][j][0] && dobar[i][j][1])kol[i+j]++; } } //cout << kol[4] << "\n"; // cout << dobar[2][2][0] << " " << dobar[2][2][1] << "\n"; int q; cin >> q; while(q--){ int x,y; cin >> x >> y; bool mogu = 0; if(!dobar[x][y][0] || !dobar[x][y][1])mogu = 1; if(kol[x+y] > 1)mogu = 1; cout << mogu << "\n"; if(mogu){ if(dobar[x][y][0] && dobar[x][y][1])kol[x+y]--; dobar[x][y][0] = dobar[x][y][1] = 0; radi(x-1,y,0); radi(x,y-1,0); radi(x,y+1,1); radi(x+1,y,1); } } return 0; }

Compilation message (stderr)

furniture.cpp: In function 'void radi(int, int, int)':
furniture.cpp:29:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   29 |     if(x <= 0 && y <= 0 && x > n || y > m)return;
      |        ~~~~~~~~~~~~~~~~~^~~~~~~~
furniture.cpp: In function 'int main()':
furniture.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
furniture.cpp:61:5: note: in expansion of macro 'ff'
   61 |     ff(i,1,n){
      |     ^~
furniture.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
furniture.cpp:62:9: note: in expansion of macro 'ff'
   62 |         ff(j,1,m)cin >> mat[i][j];
      |         ^~
furniture.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
furniture.cpp:66:5: note: in expansion of macro 'fb'
   66 |     fb(i,n,1){
      |     ^~
furniture.cpp:7:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    7 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
furniture.cpp:67:9: note: in expansion of macro 'fb'
   67 |         fb(j,m,1){
      |         ^~
furniture.cpp:69:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   69 |             if(i == n && j == m || mat[i][j] == 1)continue;
      |                ~~~~~~~^~~~~~~~~
furniture.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
furniture.cpp:74:5: note: in expansion of macro 'ff'
   74 |     ff(i,1,n){
      |     ^~
furniture.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
furniture.cpp:75:9: note: in expansion of macro 'ff'
   75 |         ff(j,1,m){
      |         ^~
furniture.cpp:76:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   76 |             if(i == 1 && j == 1 || mat[i][j] == 1)continue;
      |                ~~~~~~~^~~~~~~~~
furniture.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
furniture.cpp:81:5: note: in expansion of macro 'ff'
   81 |     ff(i,1,n){
      |     ^~
furniture.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
furniture.cpp:82:9: note: in expansion of macro 'ff'
   82 |         ff(j,1,m){
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...