Submission #378373

# Submission time Handle Problem Language Result Execution time Memory
378373 2021-03-16T15:20:18 Z qwerty234 Furniture (JOI20_furniture) C++14
0 / 100
5 ms 2028 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back

using namespace std;

const int MAXN = 1e3 + 10, inf = 2e9;

int n, m, q, a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN][MAXN], dia[MAXN][MAXN], cnt[2 * MAXN];

void dfs1(int i, int j) {
  if (i < 1 || n < i || j < 1 || m < j || b[i][j] == 0)
    return;
  b[i][j] = (b[i - 1][j] | b[i][j - 1]);
  if (b[i][j] == 0) cnt[dia[i][j]] -= (b[i][j] | c[i][j]), dfs1(i + 1, j), dfs1(i, j + 1);
}

void dfs2(int i, int j) {
  if (i < 1 || n < i || j < 1 || m < j || c[i][j] == 0)
    return;
  c[i][j] = (c[i + 1][j] | c[i][j + 1]);
  if (c[i][j] == 0) cnt[dia[i][j]] -= (b[i][j] | c[i][j]), dfs2(i - 1, j), dfs2(i, j - 1);
}

void add(int i, int j) {
  b[i][j] = c[i][j] = 0;
  cnt[dia[i][j]]--;
  dfs1(i + 1, j); dfs1(i, j + 1);
  dfs2(i - 1, j); dfs2(i, j - 1);
}

void precalc() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      b[i][j] = c[i][j] = 1;
  int cur = 0;
  for (int j = 1; j <= m; j++) {
    cur++; int ci = 1, cj = j;
    while (ci <= n && cj >= 1) {
      dia[ci][cj] = cur; cnt[cur]++;
      ci++; cj--;
    }
  }
  for (int i = 2; i <= n; i++) {
    cur++; int ci = i, cj = m;
    while (ci <= n && cj >= 1) {
      dia[ci][cj] = cur; cnt[cur]++;
      ci++; cj--;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == 1)
        add(i, j);
}

main() {
  //freopen("input.txt", "r", stdin);
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &a[i][j]);
  scanf("%d", &q);
  precalc();
  while (q--) {
    int i, j;
    scanf("%d %d", &i, &j);
    int final = cnt[dia[i][j]] - (b[i][j] & c[i][j]);
    if (final == 0) {
      printf("0\n");
      continue;
    }
    add(i, j);
    printf("1\n");
  }
}

Compilation message

furniture.cpp:59:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main() {
      |      ^
furniture.cpp: In function 'int main()':
furniture.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:64:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |       scanf("%d", &a[i][j]);
      |       ~~~~~^~~~~~~~~~~~~~~~
furniture.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |   scanf("%d", &q);
      |   ~~~~~^~~~~~~~~~
furniture.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |     scanf("%d %d", &i, &j);
      |     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Incorrect 5 ms 2028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Incorrect 5 ms 2028 KB Output isn't correct
3 Halted 0 ms 0 KB -