Submission #886346

# Submission time Handle Problem Language Result Execution time Memory
886346 2023-12-11T22:35:49 Z stefanneagu Furniture (JOI20_furniture) C++17
5 / 100
1542 ms 18264 KB
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e3 + 1;
int jd[nmax][nmax], ss[nmax][nmax], diag[2 * nmax], n, m;
bool f[nmax][nmax];
bool in(int a, int b) {
  if(a > n || b > m || min(a, b) < 0) {
    return 0;
  }
  return 1;
}
void dfs(int i, int j) {
  if(f[i][j] == 1) {
    return;
  }
  f[i][j] = 1;
  diag[i + j] --;
  ss[i - 1][j] --;
  ss[i][j - 1] --;
  jd[i + 1][j] --;
  jd[i][j + 1] --;
  if(ss[i - 1][j] == 0) {
    dfs(i - 1, j);
  }
  if(ss[i][j - 1] == 0) {
    dfs(i, j - 1);
  }
  if(jd[i + 1][j] == 0) {
    dfs(i + 1, j);
  }
  if(jd[i][j + 1] == 0) {
    dfs(i, j + 1);
  }
}
int main() {
  cin >> n >> m;
  for(int i = 0; i <= n + 1; i ++) {
    f[i][0] = 1;
    f[i][m + 1] = 1;
  }
  for(int j = 0; j <= m + 1; j ++) {
    f[0][j] = 1;
    f[n + 1][j] = 1;
  }
  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j <= m; j ++) {
      diag[i + j] ++;
      jd[i + 1][j] += 1;
      jd[i][j + 1] += 1;
      ss[i - 1][j] += 1;
      ss[i][j - 1] += 1;
    }
  }
  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j <= m; j ++) {
      int a;
      cin >> a;
      if(a == 1) {
        dfs(i, j);
        //cout << i << " " << j << endl;
      }
    }
  }
  int q;
  cin >> q;
  for(int i = 1; i <= q; i ++) {
    int a, b;
    cin >> a >> b;
    if(f[a][b] == 1 || diag[a + b] != 1) {
      cout << "1\n";
      dfs(a, b);
    } else {
      cout << "0\n";
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 6 ms 4444 KB Output is correct
3 Correct 9 ms 4444 KB Output is correct
4 Correct 12 ms 4664 KB Output is correct
5 Correct 15 ms 4660 KB Output is correct
6 Correct 16 ms 4656 KB Output is correct
7 Correct 15 ms 4444 KB Output is correct
8 Correct 21 ms 4924 KB Output is correct
9 Correct 15 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 6 ms 4444 KB Output is correct
3 Correct 9 ms 4444 KB Output is correct
4 Correct 12 ms 4664 KB Output is correct
5 Correct 15 ms 4660 KB Output is correct
6 Correct 16 ms 4656 KB Output is correct
7 Correct 15 ms 4444 KB Output is correct
8 Correct 21 ms 4924 KB Output is correct
9 Correct 15 ms 4444 KB Output is correct
10 Correct 39 ms 4668 KB Output is correct
11 Correct 10 ms 4440 KB Output is correct
12 Correct 558 ms 9684 KB Output is correct
13 Correct 118 ms 9176 KB Output is correct
14 Correct 1261 ms 10716 KB Output is correct
15 Correct 1293 ms 10876 KB Output is correct
16 Correct 1389 ms 10876 KB Output is correct
17 Correct 1542 ms 11128 KB Output is correct
18 Correct 1443 ms 11088 KB Output is correct
19 Runtime error 10 ms 18264 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -