QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#173075 | #5476. Remodeling the Dungeon | Forever_Young# | WA | 3ms | 16136kb | C++14 | 1.9kb | 2023-09-09 21:51:40 | 2023-09-09 21:51:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
const int N = 505;
char a[2 * N][2 * N];
int id[N][N];
int vst[N * N], dep[N * N], fa[N * N], color[N * N];
vector<int> e[N * N];
pair<int, int> g[N * N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i < 2 * n + 1; i++) {
scanf("%s", a[i]);
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
id[i][j] = i * m + j;
}
}
int ng = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(j < m - 1) {
if(a[i * 2 + 1][j * 2 + 2] == '.') {
e[id[i][j]].pb(id[i][j + 1]);
}else {
g[ng++] = pair<int, int>{id[i][j], id[i][j + 1]};
}
}
if(i < n - 1) {
if(a[i * 2 + 2][j * 2 + 1] == '.') {
e[id[i][j]].pb(id[i + 1][j]);
}else {
g[ng++] = pair<int, int>{id[i][j], id[i + 1][j]};
}
}
}
}
vector<int> q;
q.pb(0);
dep[0] = 0;
vst[0] = 1;
fa[0] = 0;
for(int op = 0; op < (int)q.size(); op++) {
int v = q[op];
for(int y : e[v]) {
if(!vst[y]) {
vst[y] = true;
dep[y] = dep[v] + 1;
fa[y] = v;
q.pb(y);
}
}
}
int x = n * m - 1;
fill(color, color + n * m, -1);
while(x != 0) {
color[x] = x;
x = fa[x];
}
color[0] = 0;
fill(vst, vst + n * m, 0);
q.clear();
q.pb(0);
vst[0] = 1;
for(int op = 0; op < (int)q.size(); op++) {
int v = q[op];
for(int y : e[v]) {
if(!vst[y]) {
vst[y] = true;
if(color[y] == -1) {
color[y] = color[v];
}
q.pb(y);
}
}
}
int ans = dep[n * m - 1];
for(int i = 0; i < ng; i++) {
int x = g[i].fi;
int y = g[i].se;
int fx = color[x];
int fy = color[y];
if(fx == fy) continue;
int len = dep[n * m - 1] + 1 + (dep[x] - dep[fx]) + (dep[y] - dep[fy]) - abs(dep[fx] - dep[fy]);
ans = max(ans, len);
}
printf("%d\n", ans + 1);
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 16108kb
input:
2 3 +-+-+-+ |.....| +.+.+.+ |.|.|.| +-+-+-+
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 16136kb
input:
2 3 +-+-+-+ |...|.| +.+.+.+ |.|...| +-+-+-+
output:
4
result:
ok single line: '4'
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 16088kb
input:
5 5 +-+-+-+-+-+ |...|...|.| +-+.+.+.+.+ |...|.|.|.| +.+.+.+-+.+ |.|...|.|.| +.+.+-+.+.+ |.|.....|.| +-+.+.+-+.+ |...|.....| +-+-+-+-+-+
output:
10
result:
wrong answer 1st lines differ - expected: '15', found: '10'