Submission #294104

# Submission time Handle Problem Language Result Execution time Memory
294104 2020-09-08T15:26:48 Z AlexLuchianov Furniture (JOI20_furniture) C++14
0 / 100
3 ms 1152 KB
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <queue>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 1000;
int v[5 + nmax][5 + nmax];
int init[5 + nmax][5 + nmax];
int blocks[5 + nmax * 2];
int n, m;

int solve(int x, int y) {
  std::queue<std::pair<int,int>> q;
  std::vector<std::pair<int,int>> judge;
  if(v[x][y] == 1)
    return 1;

  if(blocks[x + y] == 1)
    return 0;
  q.push({x, y});
  judge.push_back({x, y});
  v[x][y] = 1;
  blocks[x + y]--;
  int verdict = 1;
  while(0 < q.size()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();

    if(v[x - 1][y + 1] == 1) {
      if(v[x][y + 1] == 0) {
        q.push({x, y + 1});
        judge.push_back({x, y + 1});
        v[x][y + 1] = 1;
        blocks[x + y + 1]--;
        if(blocks[x + y + 1] == 0) {
          verdict = 0;
          break;
        }
      }
      if(v[x - 1][y] == 0) {
        q.push({x - 1, y});
        judge.push_back({x - 1, y});
        v[x - 1][y] = 1;
        blocks[x - 1 + y]--;
        if(blocks[x - 1 + y] == 0) {
          verdict = 0;
          break;
        }
      }
    }
    if(v[x + 1][y - 1] == 1) { 
      if(v[x][y - 1] == 0) {
        q.push({x, y - 1});
        judge.push_back({x, y - 1});
        v[x][y - 1] = 1;
        blocks[x + y - 1]--;
        if(blocks[x + y - 1] == 0) {
          verdict = 0;
          break;
        }
      }
      if(v[x + 1][y] == 0) {
        q.push({x + 1, y});
        judge.push_back({x + 1, y});
        v[x + 1][y] = 1;
        blocks[x + 1 + y]--;
        if(blocks[x + 1 + y] == 0) {
          verdict = 0;
          break;
        }
      }
    }
  }
  /* 
  std::cout << "After\n";
  for(int i = 1;i <= n; i++) {
    for(int j = 1;j <= m; j++)
      std::cout << v[i][j] << " ";
    std::cout << '\n';
  }
  std::cout << '\n';
  */

  if(verdict == 0) {
    for(int i = 0; i < judge.size(); i++) {
      int x = judge[i].first;
      int y = judge[i].second;
      v[x][y] = 0;
      blocks[x + y]++;
    }
    return 0;
  } else
    return 1;
}

int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);

  std::cin >> n >> m;
  
  for(int i = 0;i <= n + 1; i++)
    v[i][0] = v[i][m + 1] = 1;
  for(int i = 0;i <= m + 1; i++)
    v[0][i] = v[n + 1][i] = 1;

  for(int i = 1;i <= n; i++) 
    for(int j = 1;j <= m; j++) {
      std::cin >> init[i][j];
      blocks[i + j] += !init[i][j];
    }
  for(int i = 1;i <= n; i++)
    for(int j = 1;j <= m; j++)
      if(init[i][j] == 1)
        solve(i, j);
  int q;
  std::cin >> q;
  for(int i = 1;i <= q; i++) {
    int x, y;
    std::cin >> x >> y;
    std::cout << solve(x, y) << '\n';
  }
  return 0;
}

Compilation message

furniture.cpp: In function 'int solve(int, int)':
furniture.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i = 0; i < judge.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 896 KB Output is correct
2 Incorrect 3 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 896 KB Output is correct
2 Incorrect 3 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -