제출 #1337592

#제출 시각아이디문제언어결과실행 시간메모리
1337592repmannFurniture (JOI20_furniture)C++20
0 / 100
1 ms836 KiB
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
bitset <1001> A[1001], B[1001];
int IN[1002][1002];
int t, T[1001][1001], LOW[1001][1001];
vector <pair <int, int>> V;
bool DFS(int i, int j)
{
  if(B[i][j]) return 1;
  bool ret = 0;
  IN[i + 1][j]--;
  V.push_back({i + 1, j});
  if(!IN[i + 1][j]) ret |= DFS(i + 1, j);
  IN[i][j + 1]--;
  V.push_back({i, j + 1});
  if(!IN[i][j + 1]) ret |= DFS(i, j + 1);
  return ret;
}
int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> M;
  int x;
  for(int i = 1; i <= N; i++)
  {
    for(int j = 1; j <= M; j++) {cin >> x; A[i][j] = x;}
  }
  IN[0][1] = IN[N + 1][M] = 1;
  for(int i = 1; i <= N; i++)
  {
    for(int j = 1; j <= M; j++) IN[i][j] = !A[i][j] * (bool(IN[i - 1][j]) + bool(IN[i][j - 1]));
  }
  for(int i = N; i >= 1; i--)
  {
    for(int j = M; j >= 1; j--) IN[i][j] *= bool(IN[i + 1][j]) | bool(IN[i][j + 1]);
  }
//  cout << "IN:\n";
//  for(int i = 1; i <= N; i++)
//  {
//    for(int j = 1; j <= M; j++) cout << IN[i][j] << " \n"[j == M];
//  }
  B[N][M] = 1;
  cin >> Q;
  int r, c;
  while(Q--)
  {
    cin >> r >> c;
    if(!DFS(r, c))
    {
      cout << "1\n";
      IN[r][c] = 0;
    }
    else
    {
      cout << "0\n";
      for(pair <int, int> p : V) IN[p.first][p.second]++;
    }
    V.clear();
  }

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...