QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#45407#4376. Dragon slayermiaomiaoziRE 0ms0kbC++173.0kb2022-08-23 16:36:352022-08-23 16:36:36

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-23 16:36:36]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-08-23 16:36:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672346917

#ifndef LOCAL
#define LOG(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long LL;
typedef pair <int, int> PII;

constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-8;
const double PI = acos(-1);

int multi_cases = 1;

const int N = 17;

struct Wall {
    int x1, y1, x2, y2;
} walls[N];

void A_SOUL_AvA () {
    int n, m, s;
    int sx, sy, tx, ty;
    cin >> n >> m >> s;
    cin >> sx >> sy >> tx >> ty;

    for (int i = 0; i < s; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        
        if (a == c && b > d) swap(b, d);
        if (b == d && a > c) swap(a, c);
        walls[i] = {a, b, c, d};
    }

    vector vis(n, vector<int>(m));
    vector V(n, vector<int>(m));
    vector H(n, vector<int>(m));
    
    function  <bool(int, int)> dfs = [&](int x, int y) {
        if (x == tx && y == ty) {
            return true;
        }

        if (vis[x][y]) return false;
        vis[x][y] = 1;

        bool ok = false;
        if (x - 1 >= 0 && !V[x][y] && !vis[x - 1][y]) {
            ok |= dfs(x - 1, y);
        }
        if (x + 1 < n && !V[x + 1][y] && !vis[x + 1][y]) {
            ok |= dfs(x + 1, y);
        }
        if (y - 1 >= 0 && !H[x][y] && !vis[x][y - 1]) {
            ok |= dfs(x, y - 1);
        }
        if (y + 1 < m && !H[x][y + 1] && !vis[x][y + 1]) {
            ok |= dfs(x, y + 1);
        }
        return ok;
    };

    auto chk = [&](int state) {
        for (int i = 0; i < n; i++) {
            fill(all(vis[i]), 0);
            fill(all(H[i]), 0);
            fill(all(V[i]), 0);
        }
        
        for (int i = 0; i < s; i++) {
            if (state >> i & 1) continue;
            
            if (walls[i].x1 == walls[i].x2) {
                // 右往左看
                for (int j = walls[i].y1; j < walls[i].y2; j++)
                    V[walls[i].x1][j] = 1;
            }
            else {
                // 上往下看
                for (int j = walls[i].x1; j < walls[i].x2; j++)
                    H[j][walls[i].y1] = 1;
            }
        }
        return dfs(sx, sy);
    };

    vector f(1 << s, 0);

    int ans = inf;
    // 0 has     1 none
    for (int S = 0; S < 1 << s; S++) {
        if (f[S]) continue;

        bool ok = chk(S);
        int cnt = __builtin_popcount(S);

        if (ok) {
            f[S] = 1;
            ans = min(ans, cnt);
            for (int i = 0; i < s; i++) {
                f[S | (1 << i)] |= f[S];
            }
        }
    }

    cout << ans << endl;
}

int main () {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int T = 1;
    for (multi_cases && cin >> T; T; T--) {
        A_SOUL_AvA ();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: