Submission #294082

# Submission time Handle Problem Language Result Execution time Memory
294082 2020-09-08T15:07:02 Z AlexLuchianov Furniture (JOI20_furniture) C++14
0 / 100
2 ms 768 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 blocks[5 + nmax * 2];

int solve(int x, int y) {
  std::queue<std::pair<int,int>> q;
  std::vector<std::pair<int,int>> judge;
  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;
        }
      }
    }
  }
  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);

  int n, m;
  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 >> v[i][j];
      blocks[i + j] += !v[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:76: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]
   76 |     for(int i = 0; i < judge.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Incorrect 2 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Incorrect 2 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -