QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181633#5476. Remodeling the Dungeonreal_sigma_teamWA 60ms35828kbC++202.1kb2023-09-16 21:38:532023-09-16 21:38:53

Judging History

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

  • [2023-09-16 21:38:53]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:35828kb
  • [2023-09-16 21:38:53]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

using ll = long long;

const int N = 500 + 5;

char a[N * 2][N * 2];
int n, m;

int vc(int x, int y) {
    return x + y * n;
}

int ok(int x, int y) {
    return x > -1 && y > -1 && x < n && y < m;
}

vector<int> gr[N * N], con[N * N];

int p[N * N], dist[N * N], in[N * N], out[N * N], t = 0;

void dfs(int v) {
    in[v] = t++;
    for (int u: gr[v]) {
        if (u != p[v]) {
            p[u] = v;
            dist[u] = dist[v] + 1;
            dfs(u);
        }
    }
    out[v] = t++;
}

bool subtree(int u, int v) {
    return in[v] < in[u] && out[u] < out[v];
}

int used[N];
int ans = 0;

void go(int v, int P, int D) {
    used[v] = 1;
    for (int u: con[v]) {
        if (!subtree(u, P))
            ans = max(ans, D + dist[u]);
    }
    for (int u: gr[v]) {
        if (u != p[P] && used[u] == 0)
            go(u, P, D + 1);
    }
}

void solve() {

    cin >> n >> m;

    for (int i = 0; i < n * 2 + 1; i++) {
        for (int j = 0; j < m * 2 + 1; j++) {
            cin >> a[i][j];
        }
    }
    int dx[] = {0, 0, -1, 1};
    int dy[] = {1, -1, 0, 0};
    for (int i = 0, x = 1; i < n && x < n * 2 + 1; i++, x += 2) {
        for (int j = 0, y = 1; j < m && y < m * 2 + 1; j++, y += 2) {
            for (int d = 0; d < 4; d++) {
                int ni = i + dx[d], nj = j + dy[d], nx = x + dx[d], ny = y + dy[d];
                if (a[nx][ny] == '.') {
                    gr[vc(i, j)].push_back(vc(ni, nj));
                } else if (ok(ni, nj)) {
                    con[vc(i, j)].push_back(vc(ni, nj));
                }
            }
        }
    }
    p[0] = -1;
    dist[0] = 1;
    dfs(0);
    int en = vc(n - 1, m - 1);
    ans = dist[en];
    int ds = 1, cr = en;
    while (cr != -1) {
        go(cr, cr, ds);
        cr = p[cr];
        ds++;
    }
    cout << ans << '\n';
}

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#else
    freopen("input.txt", "r", stdin);
#endif
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 15436kb

input:

2 3
+-+-+-+
|.....|
+.+.+.+
|.|.|.|
+-+-+-+

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 6ms
memory: 15364kb

input:

2 3
+-+-+-+
|...|.|
+.+.+.+
|.|...|
+-+-+-+

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 1ms
memory: 15440kb

input:

5 5
+-+-+-+-+-+
|...|...|.|
+-+.+.+.+.+
|...|.|.|.|
+.+.+.+-+.+
|.|...|.|.|
+.+.+-+.+.+
|.|.....|.|
+-+.+.+-+.+
|...|.....|
+-+-+-+-+-+

output:

15

result:

ok single line: '15'

Test #4:

score: -100
Wrong Answer
time: 60ms
memory: 35828kb

input:

500 500
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...

output:

3597

result:

wrong answer 1st lines differ - expected: '4693', found: '3597'