# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1038625 | Tepeyac | Mecho (IOI09_mecho) | C++11 | 186 ms | 65536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct Cell
{
int x, y;
};
int n, s;
pair<int, int> pos;
char ma[801][801];
int enj[801][801];
bool vb[801][801];
int pa[801][801];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool isvalid(int i, int j)
{
return i >= 1 && i <= n && j >= 1 && j <= n;
}
bool monotone(int m)
{
queue<Cell> q;
memset(pa, 0, sizeof(pa));
memset(vb, false, sizeof(vb));
Cell nodo = {pos.first, pos.second};
q.push(nodo);
pa[nodo.x][nodo.y] = m;
vb[pos.first][pos.second] = true;
while(!q.empty())
{
Cell Nodo = q.front();
q.pop();
for(int i = 0; i < 4; ++i)
{
for(int j = 1; j <= s; ++j)
{
int nx = Nodo.x + j * dx[i];
int ny = Nodo.y + j * dy[i];
if(!isvalid(nx, ny) || ma[nx][ny] == 'H' || ma[nx][ny] == 'T' && pa[nx][ny] + 1 >= enj[nx][ny] && vb[nx][ny])
break;
if(ma[nx][ny] == 'D')
{
return true;
}
vb[nx][ny] = true;
pa[nx][ny] = pa[Nodo.x][Nodo.y] + 1;
q.push({nx, ny});
}
}
}
return false;
}
int BSOTA(int a, int b)
{
while(a + 1 < b)
{
int m = (a + b) / 2;
if(monotone(m))
{
a = m;
} else
{
b = m;
}
}
return a;
}
int main()
{
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> s;
queue<pair<int, int>> q;
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
cin >> ma[i][j];
if(ma[i][j] == 'H')
{
q.push({i, j});
enj[i][j] = 0;
}
else
{
enj[i][j] = -1;
}
if(ma[i][j] == 'M')
{
pos = {i, j};
}
}
}
while(!q.empty())
{
int i2 = q.front().first, j2 = q.front().second;
q.pop();
for(int i = 0; i < 4; ++i)
{
int nx = dx[i] + i2;
int ny = dy[i] + j2;
if(isvalid(nx, ny) && ma[nx][ny] != 'D' && ma[nx][ny] != 'T' && ma[nx][ny] != 'H' && enj[nx][ny] == -1)
{
q.push({nx, ny});
enj[nx][ny] = enj[i2][j2] + 1;
}
}
}
int maxx = enj[pos.first][pos.second];
cout << BSOTA(0, maxx - 1) - 1 << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |