Submission #1213821

#TimeUsernameProblemLanguageResultExecution timeMemory
1213821mychecksedadFurniture (JOI20_furniture)C++20
0 / 100
1 ms1516 KiB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1000+100, M = 1e5+10, K = 52, MX = 30;


int n, m, q, a[N][N];
array<int, 2> b[N*N];
bitset<N> vis[N];
bitset<N> ANS[N];

bool ok(int x, int y){
  return x >= 1 && x <= n && y >= 1 && y <= m;
}
void solve(){
  cin >> n >> m;
  vector<vi> T(n + 1, vi(m + 1, MOD));
  
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= m; ++j){
      cin >> a[i][j];
      if(a[i][j]) T[i][j] = 0;
    }
  }
  cin >> q;
  for(int i = 1; i <= q; ++i){
    cin >> b[i][0] >> b[i][1];
    a[b[i][0]][b[i][1]] = 1;
    T[b[i][0]][b[i][1]] = i;
    ANS[i] = 1;
  }

  vector<vector<pii>> par(n + 1, vector<pii>(m + 1, {-1, -1}));

  priority_queue<array<int, 3>> Q;
  Q.push({0, 1, 1});
  while(!Q.empty()){
    int x = Q.top()[1];
    int y = Q.top()[2];
    Q.pop();
    // cerr << x << ' ' << y << ' ' << 
    int nx = x + 1, ny = y;
    if(ok(nx, ny) && !vis[nx][ny]){
      Q.push({T[nx][ny], nx, ny});
      vis[nx][ny] = 1;
      par[nx][ny] = {x, y};
    }
    nx = x, ny = y + 1;
    if(ok(nx, ny) && !vis[nx][ny]){
      Q.push({T[nx][ny], nx, ny});
      vis[nx][ny] = 1;
      par[nx][ny] = {x, y};
    }
  }

  int x = n, y = m;
  while(x != -1){
    ANS[x][y] = 1;
    tie(x, y) = par[x][y];
  }

  for(int i = 1; i <= q; ++i){
    cout << !ANS[b[i][0]][b[i][1]] << '\n';
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...