Submission #886334

# Submission time Handle Problem Language Result Execution time Memory
886334 2023-12-11T22:15:49 Z stefanneagu Furniture (JOI20_furniture) C++17
5 / 100
1231 ms 18768 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int nmax = 1e3 + 5;
int jd[nmax][nmax], ss[nmax][nmax], diag[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(!in(i, j) || 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);
  }
}
int32_t 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 7 ms 4444 KB Output is correct
4 Correct 12 ms 4660 KB Output is correct
5 Correct 13 ms 4444 KB Output is correct
6 Correct 16 ms 4444 KB Output is correct
7 Correct 15 ms 4660 KB Output is correct
8 Correct 15 ms 4444 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 7 ms 4444 KB Output is correct
4 Correct 12 ms 4660 KB Output is correct
5 Correct 13 ms 4444 KB Output is correct
6 Correct 16 ms 4444 KB Output is correct
7 Correct 15 ms 4660 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 15 ms 4444 KB Output is correct
10 Correct 40 ms 4700 KB Output is correct
11 Correct 10 ms 4444 KB Output is correct
12 Correct 523 ms 17744 KB Output is correct
13 Correct 118 ms 17108 KB Output is correct
14 Incorrect 1231 ms 18768 KB Output isn't correct
15 Halted 0 ms 0 KB -