# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
72163 | cat > /dev/null (#118) | 수중 미로 (FXCUP3_aqua) | C++17 | 332 ms | 5096 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <queue>
#define N 910
#define INF 0x3fffffff
using namespace std;
int n;
int d[N][N];
char map[N][N];
int dx[]={-1,0,1,0}, dy[]={0,-1,0,1};
struct st
{
int x, y, e;
bool operator<(const st &hs) const
{
return e>hs.e;
}
bool in_bound()
{
return 0<=x && x<n && 0<=y && y<n;
}
void move(int way)
{
x += dx[way];
y += dy[way];
}
char state()
{
return map[x][y];
}
};
priority_queue<st> q;
st m, h;
int main()
{
scanf("%d", &n);
for(int i=0; i<n; ++i)
{
scanf("%s", map[i]);
for(int j=0; j<n; ++j)
{
d[i][j] = INF;
if(map[i][j] == 'M')
m = {i, j, 0};
if(map[i][j] == 'H')
h = {i, j, 0};
}
}
q.push(m);
d[m.x][m.y] = 1;
while(!q.empty())
{
st now = q.top();
q.pop();
if(d[now.x][now.y] <= now.e)
continue;
d[now.x][now.y] = now.e;
if(now.x==h.x && now.y==h.y)
break;
for(int w=0; w<4; ++w)
{
st wall = now;
while(wall.in_bound() && wall.state()!='W')
wall.move(w);
if(wall.in_bound())
{
int dep;
for(dep=0; wall.in_bound() && wall.state()=='W'; ++dep)
wall.move(w);
if(wall.in_bound())
while(wall.in_bound() && wall.state()!='W')
{
if(d[wall.x][wall.y] > now.e+dep*dep)
{
d[wall.x][wall.y] = now.e+dep*dep+1;
q.push({wall.x, wall.y, now.e+dep*dep});
}
wall.move(w);
}
}
}
}
printf("%d", d[h.x][h.y]==INF? -1 : d[h.x][h.y]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |