QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94053 | #5476. Remodeling the Dungeon | whatever# | RE | 5ms | 8944kb | C++17 | 1.8kb | 2023-04-05 09:15:49 | 2023-04-05 09:15:53 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a, I = b; i <= I; ++i)
#define per(i, a, b) for (int i = a, I = b; i >= I; --i)
using namespace std;
const int N = 200005;
int h, w, n, d1[N], d2[N], fa[N], X, Y, v1, vn, bel[N];
vector<int> e[N];
int ID(int i, int j) {
return 1ll * (i - 1) * w + j;
}
void add_edge(int u, int v) {
e[u].push_back(v);
e[v].push_back(u);
}
void dfs(int u, int *dep) {
for (auto v : e[u]) {
if (v == fa[u]) continue;
dep[v] = dep[u] + 1;
fa[v] = u;
dfs(v, dep);
}
}
void dfs1(int u) {
for (auto v : e[u]) {
if (bel[v]) continue;
bel[v] = bel[u];
dfs1(v);
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> h >> w, n = h * w;
rep(i, 1, 2 * h + 1) {
string s; cin >> s;
if (i == 1 || i == 2 * h + 1) continue;
if (i % 2 == 0) {
rep(j, 1, w - 1) {
if (s[2 * j] == '.') add_edge(ID(i / 2, j), ID(i / 2, j + 1));
}
} else {
rep(j, 1, w) {
if (s[2 * j - 1] == '.') add_edge(ID(i / 2, j), ID(i / 2 + 1, j));
}
}
}
dfs(n, d2);
memset(fa, 0, sizeof fa);
dfs(1, d1);
int ans = d1[n], cnt = 0;
for (int u = n; u; u = fa[u]) bel[u] = ++cnt;
for (int u = n; u; u = fa[u]) dfs1(u);
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
rep(i, 1, h) rep(j, 1, w) {
int u = ID(i, j);
rep(d, 0, 3) {
int i1 = i + dx[d], j1 = j + dy[d];
if (i1 < 1 || i1 > h || j1 < 1 || j1 > w) continue;
int v = ID(i1, j1);
if (bel[u] < bel[v]) ans = max(ans, d2[u] + d1[v] + 1);
}
}
cout << ans + 1 << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 8880kb
input:
2 3 +-+-+-+ |.....| +.+.+.+ |.|.|.| +-+-+-+
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 8944kb
input:
2 3 +-+-+-+ |...|.| +.+.+.+ |.|...| +-+-+-+
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 1ms
memory: 8900kb
input:
5 5 +-+-+-+-+-+ |...|...|.| +-+.+.+.+.+ |...|.|.|.| +.+.+.+-+.+ |.|...|.|.| +.+.+-+.+.+ |.|.....|.| +-+.+.+-+.+ |...|.....| +-+-+-+-+-+
output:
15
result:
ok single line: '15'
Test #4:
score: -100
Runtime Error
input:
500 500 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...