QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47671#4376. Dragon slayerckiseki#WA 157ms3592kbC++2.7kb2022-09-10 15:52:242022-09-10 15:52:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-10 15:52:25]
  • 评测
  • 测评结果:WA
  • 用时:157ms
  • 内存:3592kb
  • [2022-09-10 15:52:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
static constexpr int maxn = 16;

int vis[maxn][maxn], visc;
int a[2][maxn][maxn];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t; cin >> t;
    while (t--) {
        int n, m, k; cin >> n >> m >> k;
        int xs, ys, xt, yt;
        cin >> xs >> ys >> xt >> yt;
        vector<pair<pair<int, int>, pair<int, int>>> b(k);
        for (auto &[lhs, rhs] : b) {
            cin >> lhs.first >> lhs.second;
            cin >> rhs.first >> rhs.second;
        }

        auto gao = [&](const pair<pair<int, int>, pair<int, int>> &l){
            const auto &[lhs, rhs] = l;
            if (lhs.first == rhs.first) {
                const auto &[p, q] = minmax(lhs.second, rhs.second);
                for (int i = p; i < q; ++i)
                    a[0][lhs.first][i] = visc;
            } else {
                const auto &[p, q] = minmax(lhs.first, rhs.first);
                for (int i = p; i < q; ++i)
                    a[1][i][lhs.second] = visc;
            }
        };

        auto good = [&](int s) {
            ++visc;
            for (int i = 0; i < k; ++i) {
                if (!((s >> i) & 1))
                    gao(b[i]);
            }
            queue<pair<int, int>> bfs;
            bfs.emplace(xs, ys);
            vis[xs][ys] = visc;
            while (not bfs.empty()) {
                auto [x, y] = bfs.front();
                bfs.pop();
                if (int nx = x, ny = y + 1; ny < m) {
                    if (vis[nx][ny] != visc and a[1][nx][ny] != visc) {
                        vis[nx][ny] = visc;
                        bfs.emplace(nx, ny);
                    }
                } 
                if (int nx = x, ny = y - 1; ny >= 0) {
                    if (vis[nx][ny] != visc and a[1][nx][ny] != visc) {
                        vis[nx][ny] = visc;
                        bfs.emplace(nx, ny);
                    }
                } 
                if (int nx = x + 1, ny = y; nx < n) {
                    if (vis[nx][ny] != visc and a[0][nx][ny] != visc) {
                        vis[nx][ny] = visc;
                        bfs.emplace(nx, ny);
                    }
                } 
                if (int nx = x - 1, ny = y; nx >= 0) {
                    if (vis[nx][ny] != visc and a[0][nx][ny] != visc) {
                        vis[nx][ny] = visc;
                        bfs.emplace(nx, ny);
                    }
                } 
            }
            return vis[xt][yt] == visc;
        };

        int ans = k;
        const int S = 1 << k;
        for (int s = 0; s < S; ++s) {
            if (good(s)) ans = min(ans, __builtin_popcount(s));
        }
        cout << ans << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 157ms
memory: 3592kb

input:

10
4 4 4 0 2 3 3
0 2 4 2
1 3 1 0
2 4 2 1
3 1 3 4
3 2 2 0 0 2 1
0 1 3 1
1 0 1 2
3 2 2 0 0 2 1
2 1 2 2
1 0 1 1
15 15 15 3 12 4 1
8 0 8 15
1 11 15 11
1 1 1 15
3 1 3 15
0 10 14 10
14 1 14 14
8 1 8 15
1 5 14 5
0 15 14 15
0 4 14 4
0 2 15 2
11 0 11 15
4 1 4 15
1 11 15 11
1 12 14 12
15 15 15 8 5 14 0
0 12 1...

output:

1
2
0
4
5
5
1
4
1
0

result:

wrong answer 4th lines differ - expected: '5', found: '4'