답안 #886332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886332 2023-12-11T22:13:37 Z stefanneagu Furniture (JOI20_furniture) C++17
5 / 100
1270 ms 18516 KB
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e3 + 1;
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(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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 5 ms 4444 KB Output is correct
3 Correct 7 ms 4644 KB Output is correct
4 Correct 12 ms 4444 KB Output is correct
5 Correct 13 ms 4440 KB Output is correct
6 Correct 15 ms 4444 KB Output is correct
7 Correct 21 ms 4440 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 15 ms 4664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 5 ms 4444 KB Output is correct
3 Correct 7 ms 4644 KB Output is correct
4 Correct 12 ms 4444 KB Output is correct
5 Correct 13 ms 4440 KB Output is correct
6 Correct 15 ms 4444 KB Output is correct
7 Correct 21 ms 4440 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 15 ms 4664 KB Output is correct
10 Correct 39 ms 4668 KB Output is correct
11 Correct 11 ms 4444 KB Output is correct
12 Correct 526 ms 11628 KB Output is correct
13 Correct 118 ms 10820 KB Output is correct
14 Incorrect 1270 ms 18516 KB Output isn't correct
15 Halted 0 ms 0 KB -