# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
53583 | ho94949 | Mecho (IOI09_mecho) | C++17 | 310 ms | 6744 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int N, S;
char arr[1024][1024];
int dist[1024][1024];
bool vis[1024][1024];
bool valid(int x, int y)
{
return 0<=x&&x<N&&0<=y&&y<N;
}
bool can(int t)
{
queue<tuple<int, int, int> > Q;
memset(vis, false, sizeof(vis));
for(int i=0; i<N; ++i)
for(int j=0; j<N; ++j)
if(arr[i][j] == 'M')
{
if(dist[i][j] <= t*S) return false;
Q.emplace(t*S, i, j);
}
while(!Q.empty())
{
int di, x, y; tie(di, x, y) = Q.front(); Q.pop();
if(arr[x][y] == 'D') return true;
for(int d=0; d<4; ++d)
{
int nx = x+"1210"[d]-'1';
int ny = y+"0121"[d]-'1';
if(!valid(nx, ny)) continue;
if(arr[nx][ny] != 'G' && arr[nx][ny] != 'D') continue;
if(dist[nx][ny] <= di+1) continue;
if(vis[nx][ny]) continue;
Q.emplace(di+1, nx, ny);
vis[nx][ny] = true;
}
}
return false;
}
void init()
{
memset(dist, 0x3f, sizeof dist);
queue<pair<int, int> > Q;
for(int i=0; i<N; ++i)
for(int j=0; j<N; ++j)
{
if(arr[i][j] == 'H')
{
Q.emplace(i, j);
dist[i][j] = 0;
}
}
while(!Q.empty())
{
int x, y; tie(x, y) = Q.front(); Q.pop();
for(int d=0;d<4;++d)
{
int nx = x+"1210"[d] - '1';
int ny = y+"0121"[d] - '1';
if(!valid(nx, ny)) continue;
if(arr[nx][ny] != 'G' && arr[nx][ny] != 'M') continue;
if(dist[nx][ny] != INF) continue;
dist[nx][ny] = dist[x][y]+S;
Q.emplace(nx, ny);
}
}
}
int main()
{
scanf("%d%d", &N, &S);
for(int i=0; i<N; ++i)
scanf("%s", arr[i]);
int lo = -1; //pos
int hi = N*N; //impos
init();
while(lo+1!=hi)
{
int mi = (lo+hi)/2;
if(can(mi)) lo = mi;
else hi = mi;
}
printf("%d\n", lo);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |