Submission #500975

#TimeUsernameProblemLanguageResultExecution timeMemory
500975AmirElarbiFurniture (JOI20_furniture)C++14
0 / 100
10 ms4428 KiB
#include <bits/stdc++.h> #define vi vector<int> #define ve vector #define ll long long #define vf vector<float> #define vll vector<pair<ll,ll>> #define ii pair<int,int> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 1e9 #define eps 1e-7 #define eps1 1e-25 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 1e5+5 #define V 450 using namespace std; const int MOD = 1e9+7; const int nax = 1000005; short grid[1005][1005],vis[1005][1005]; int cnt[nax]; int n,m; int mov[4][2] = {{0,1},{1,0},{-1,0},{0,-1}}; int dfs(int x, int y){ if(x == n && y == m) return 0; if(x > n || y > m) return 1; if(grid[x][y]==1) return 1; if(vis[x][y]) return grid[x][y]; vis[x][y] = 1; grid[x][y] = min(dfs(x+1,y),dfs(x,y+1)); cnt[x+y]+=(grid[x][y]==0); return grid[x][y]; } void upd(int x, int y){ for (int i = 0; i < 4; ++i) { int nx = x + mov[i][0], ny = y + mov[i][1]; if(nx < 1 || ny < 1 || nx >n || ny > m ||grid[nx][ny] == 1||(nx == 1 && ny == 1)||(nx == n && ny == m)) continue; if(grid[nx-1][ny]&& grid[nx][ny-1]){ grid[nx][ny] = 1; } if(grid[nx+1][ny] && grid[nx][ny+1]){ grid[nx][ny] = 1; } if(grid[nx][ny]){ cnt[nx+ny]--; upd(nx,ny); } } } int main(){ optimise; cin>>n >>m; for (int i = 0; i < nax; ++i) { for (int j = 0; j < nax; ++j) { grid[i][j] = 1; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> grid[i][j]; if(grid[i][j] == 0) grid[i][j] = 2; } } dfs(1,1); grid[n][m] = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if(grid[i][j]==2) grid[i][j] = 1; } } int q; cin >>q; while(q--){ int x,y; cin >> x >> y; if(grid[x][y] == 1){ cout << 1 << endl; continue; } else if(cnt[x+y] <= 1){ cout << 0 << endl; continue; } cout << 1 << endl; grid[x][y] = 1; cnt[x+y]--; upd(x,y); } }

Compilation message (stderr)

furniture.cpp: In function 'int main()':
furniture.cpp:62:24: warning: iteration 1005 invokes undefined behavior [-Waggressive-loop-optimizations]
   62 |             grid[i][j] = 1;
      |             ~~~~~~~~~~~^~~
furniture.cpp:60:27: note: within this loop
   60 |         for (int j = 0; j < nax; ++j)
      |                         ~~^~~~~
furniture.cpp:62:24: warning: iteration 1005 invokes undefined behavior [-Waggressive-loop-optimizations]
   62 |             grid[i][j] = 1;
      |             ~~~~~~~~~~~^~~
furniture.cpp:58:23: note: within this loop
   58 |     for (int i = 0; i < nax; ++i)
      |                     ~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...