QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#517021#9164. Toyskittles1412Compile Error//C++173.2kb2024-08-13 03:03:532024-08-13 03:03:53

Judging History

你现在查看的是最新测评结果

  • [2024-08-13 03:03:53]
  • 评测
  • [2024-08-13 03:03:53]
  • 提交

answer

#include "template.hpp"

using P = pair<int, int>;

P& operator+=(P& a, const P& b) {
    a.first += b.first;
    a.second += b.second;
    return a;
}

P operator+(P a, const P& b) {
    return a += b;
}

template <typename T>
auto&& get(vector<vector<T>>& arr, const P& p) {
    return arr[p.first][p.second];
}

constexpr P DIRS[4] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

struct Inter {
    int l, r;

    Inter& operator&=(const Inter& o) {
        l = max(l, o.l);
        r = min(r, o.r);
        return *this;
    }

    friend Inter operator&(Inter a, const Inter& b) {
        return a &= b;
    }

    bool is_valid() const {
        return l <= r;
    }

    friend ostream& operator<<(ostream& out, const Inter& o) {
        return out << "[" << o.l << ", " << o.r << "]";
    }
};

bool inters(const Inter& a, const Inter& b) {
    return (a & b).is_valid();
}

vector<vector<Inter>> solve_hori(const vector<vector<bool>>& arr, int len) {
    int n = sz(arr), m = sz(arr[0]);

    vector ans(n, vector(m, Inter {}));

    for (int i = 0; i < n; i++) {
        vector<int> l_bad(m), r_bad(m);

        for (int j = 0, prv = -1; j < m; j++) {
            if (!arr[i][j]) {
                prv = j;
            }
            l_bad[j] = prv;
        }
        for (int j = m - 1, prv = m; j >= 0; j--) {
            if (!arr[i][j]) {
                prv = j;
            }
            r_bad[j] = prv;
        }

        for (int j = 0; j < m; j++) {
            ans[i][j] = Inter {0, m - len} & Inter {j - len + 1, j} &
                        Inter {l_bad[j] + 1, m} & Inter {0, r_bad[j] - len};
            dbg(i, j, ans[i][j]);
        }
    }

    return ans;
}

void solve() {
    int n, m, kh, kv, xh, yh, xv, yv, xt = -1, yt = -1;
    cin >> m >> n >> kh >> kv >> yh >> xh >> yv >> xv;

    vector arr(n, vector(m, false));
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            arr[i][j] = s[j] != 'X';
            if (s[j] == '*') {
                xt = i;
                yt = j;
            }
        }
    }

    auto inters_h = solve_hori(arr, kh),
         inters_v = transposed(solve_hori(transposed(arr), kv));

    vector vis(n, vector(m, char(false)));

    auto ibs = [&](const P& p) -> bool {
        auto& [x, y] = p;
        return 0 <= x && x < n && 0 <= y && y < m;
    };

    vector<P> q;
    auto push = [&](const P& p) {
        if (!ibs(p) || get(vis, p)) {
            return;
        }
        dbg(p);
        get(vis, p) = true;
        q.push_back(p);
    };

    push({xh, yv});

    while (sz(q)) {
        auto u = q.back();
        q.pop_back();

        for (auto& du : DIRS) {
            auto v = u + du;

            if (!ibs(v)) {
                continue;
            }

            if (inters(get(inters_h, u), get(inters_h, v)) &&
                inters(get(inters_v, u), get(inters_v, v))) {
                push(v);
            }
        }
    }

    if (vis[xt][yt]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    init_io();

    solve();
}

Details

answer.code:1:10: fatal error: template.hpp: No such file or directory
    1 | #include "template.hpp"
      |          ^~~~~~~~~~~~~~
compilation terminated.