Submission #677788

# Submission time Handle Problem Language Result Execution time Memory
677788 2023-01-04T11:16:36 Z bashkort Furniture (JOI20_furniture) C++17
100 / 100
305 ms 12176 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int N = 1004, dx[]{0, 0, -1, 1}, dy[]{-1, 1, 0, 0};

int c[N][N], dead[N][N], cnt[2 * N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    queue<pair<int, int>> consider;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> c[i][j];

            if (c[i][j]) {
                consider.emplace(i, j);
            }

            cnt[i + j] += 1;
        }
    }
    for (int j = 2; j <= m + 1; ++j) {
        c[0][j] = 1;
        consider.emplace(0, j);
    }
    for (int i = 2; i <= n + 1; ++i) {
        c[i][0] = 1;
        consider.emplace(i, 0);
    }
    for (int j = 0; j <= m - 1; ++j) {
        c[n + 1][j] = 1;
        consider.emplace(n + 1, j);
    }
    for (int i = 0; i <= n - 1; ++i) {
        c[i][m + 1] = 1;
        consider.emplace(i, m + 1);
    }


    auto normalize = [&]() {
        while (!consider.empty()) {
            auto [i, j] = consider.front();
            consider.pop();

            if (dead[i][j]) {
                continue;
            }

            if (c[i][j] || i && j && dead[i - 1][j] && dead[i][j - 1] || dead[i][j + 1] && dead[i + 1][j]) {
                dead[i][j] = 1;
            }

            if (dead[i][j]) {
                for (int k = 0; k < size(dx); ++k) {
                    int ni = i + dx[k], nj = j + dy[k];
                    if (ni > 0 && nj > 0 && ni < n + 1 && nj < m + 1 && !dead[ni][nj]) {
                        consider.emplace(ni, nj);
                    }
                }
                if (i && i <= n && j && j <= m) {
                    cnt[i + j] -= 1;
                }
            }
        }
    };

    normalize();

    int q;
    cin >> q;

    while (q--) {
        int i, j;
        cin >> i >> j;

        if (dead[i][j]) {
            c[i][j] = 1;
            cout << "1\n";
            continue;
        }

        if (cnt[i + j] > 1) {
            c[i][j] = 1;

            consider.emplace(i, j);
            normalize();

            cout << "1\n";
        } else {
            cout << "0\n";
        }
    }

    return 0;
}

Compilation message

furniture.cpp: In lambda function:
furniture.cpp:57:53: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   57 |             if (c[i][j] || i && j && dead[i - 1][j] && dead[i][j - 1] || dead[i][j + 1] && dead[i + 1][j]) {
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:57:89: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   57 |             if (c[i][j] || i && j && dead[i - 1][j] && dead[i][j - 1] || dead[i][j + 1] && dead[i + 1][j]) {
      |                                                                          ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:62:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 for (int k = 0; k < size(dx); ++k) {
      |                                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1156 KB Output is correct
4 Correct 3 ms 1108 KB Output is correct
5 Correct 3 ms 1236 KB Output is correct
6 Correct 3 ms 1236 KB Output is correct
7 Correct 3 ms 1240 KB Output is correct
8 Correct 3 ms 1236 KB Output is correct
9 Correct 3 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1156 KB Output is correct
4 Correct 3 ms 1108 KB Output is correct
5 Correct 3 ms 1236 KB Output is correct
6 Correct 3 ms 1236 KB Output is correct
7 Correct 3 ms 1240 KB Output is correct
8 Correct 3 ms 1236 KB Output is correct
9 Correct 3 ms 1236 KB Output is correct
10 Correct 10 ms 1276 KB Output is correct
11 Correct 3 ms 728 KB Output is correct
12 Correct 165 ms 11008 KB Output is correct
13 Correct 71 ms 11864 KB Output is correct
14 Correct 257 ms 12176 KB Output is correct
15 Correct 275 ms 10708 KB Output is correct
16 Correct 273 ms 10892 KB Output is correct
17 Correct 296 ms 11212 KB Output is correct
18 Correct 232 ms 10988 KB Output is correct
19 Correct 305 ms 11340 KB Output is correct
20 Correct 209 ms 11368 KB Output is correct
21 Correct 290 ms 11376 KB Output is correct