# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100781 | Alexa2001 | Mecho (IOI09_mecho) | C++17 | 239 ms | 7032 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 808, inf = Nmax * Nmax;
int n, S;
char a[Nmax][Nmax];
int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };
int tmp[Nmax][Nmax], D[Nmax][Nmax];
queue< pair<int,int> > q;
void prec()
{
int i, j, x, y, X, Y;
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
tmp[i][j] = inf;
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
if(a[i][j] == 'H')
{
q.push({i, j});
tmp[i][j] = 0;
}
while(q.size())
{
tie(x, y) = q.front();
q.pop();
for(i=0; i<4; ++i)
{
X = x + dx[i];
Y = y + dy[i];
if((a[X][Y] == 'G' || a[X][Y] == 'M') && tmp[X][Y] == inf)
{
tmp[X][Y] = tmp[x][y] + 1;
q.push({X, Y});
}
}
}
}
bool check(int T)
{
while(q.size()) q.pop();
int i, j, x, y, X, Y;
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
{
if(a[i][j] == 'M')
x = i, y = j;
D[i][j] = inf;
}
if(!(T < tmp[x][y])) return 0;
q.push({x, y});
D[x][y] = 0;
while(q.size())
{
tie(X, Y) = q.front();
q.pop();
for(i=0; i<4; ++i)
{
x = X + dx[i];
y = Y + dy[i];
if(a[x][y] == 'D') return 1;
if(a[x][y] == 'G' && D[X][Y] + 1 < S * (tmp[x][y] - T) && D[x][y] == inf)
{
D[x][y] = D[X][Y] + 1;
q.push({x, y});
}
}
}
return 0;
}
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false);
cin >> n >> S;
int i;
for(i=1; i<=n; ++i) cin >> (a[i] + 1);
prec();
int st, dr, mid;
st = 0; dr = n * n;
while(st <= dr)
{
mid = (st + dr) / 2;
if(check(mid)) st = mid + 1;
else dr = mid - 1;
}
cout << dr << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |