Submission #402716

# Submission time Handle Problem Language Result Execution time Memory
402716 2021-05-12T09:42:50 Z KoD Furniture (JOI20_furniture) C++17
0 / 100
2 ms 588 KB
#include <bits/stdc++.h>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { ++itr; }
        constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr rep(const usize first, const usize last) noexcept : first(first), last(std::max(first, last)) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

template <class T> using Vec = std::vector<T>;

void JOI20_furniture_main() {
    usize N, M;
    std::cin >> N >> M;
    Vec<Vec<char>> grid(N, Vec<char>(M));
    for (auto& v : grid) {
        for (auto& x : v) {
            std::cin >> x;
        }
    }
    Vec<std::set<usize>> crit(N);
    {
        Vec<Vec<int>> state(N, Vec<int>(M));
        Vec<Vec<bool>> done(N, Vec<bool>(M));
        std::queue<std::pair<usize, usize>> que;
        const auto push = [&](const usize i, const usize j) {
            if (grid[i][j] == '0' and !done[i][j]) {
                done[i][j] = true;
                que.emplace(i, j);
            }
        };
        push(0, 0);
        while (!que.empty()) {
            const auto [i, j] = que.front();
            que.pop();
            state[i][j] |= 1;
            if (i + 1 < N) {
                push(i + 1, j);
            }
            if (j + 1 < M) {
                push(i, j + 1);
            }
        }
        done = Vec<Vec<bool>>(N, Vec<bool>(M));
        push(N - 1, M - 1);
        while (!que.empty()) {
            const auto [i, j] = que.front();
            que.pop();
            state[i][j] |= 2;
            if (i > 0) {
                push(i - 1, j);
            }
            if (j > 0) {
                push(i, j - 1);
            }
        }
        for (const auto i : rep(0, N)) {
            for (const auto j : rep(0, M)) {
                if (state[i][j] == 3) {
                    crit[i].insert(j);
                }
            }
        }
    }
    usize Q;
    std::cin >> Q;
    while (Q--) {
        usize i, j;
        std::cin >> i >> j;
        i -= 1;
        j -= 1;
        if (crit[i].find(j) == crit[i].end()) {
            std::cout << 1 << '\n';
            continue;
        }
        const usize up = (i == 0 ? 0 : *crit[i - 1].rbegin());
        const usize down = (i + 1 == N ? M - 1 : *crit[i + 1].begin());
        if (up <= j and j <= down) {
            std::cout << 0 << '\n';
            continue;
        }
        std::cout << 1 << '\n';
        if (up <= j) {
            for (; i < N and *crit[i].begin() <= j; ++i) {
                crit[i].erase(crit[i].lower_bound(j), crit[i].end());
            }
        }
        if (j <= down) {
            while (*crit[i].rbegin() >= j) {
                crit[i].erase(crit[i].begin(), crit[i].upper_bound(j));
                if (i == 0) {
                    break;
                }
                i -= 1;
            }
        }
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    JOI20_furniture_main();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -