# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
104093 | Erkhemkhuu | Mecho (IOI09_mecho) | C++17 | 299 ms | 6392 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
int movex[4] = {-1, 0, 1, 0};
int movey[4] = {0, 1, 0, -1};
char maps[805][805];
int beeStep[805][805], meStep[805][805], n, Mx, My, s, Dx, Dy;
queue <pair <int, int> > bee, me;
bool check(int x, int y) {
if(x >= 0 && x < n && y >= 0 && y < n) return true;
return false;
}
inline bool can(int mid) {
if(mid >= beeStep[Mx][My]) return false;
int curx, cury, curstep, i, j, i1, movexx, moveyy;
me.push(mp(Mx, My));
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
meStep[i][j] = 1e9;
meStep[Mx][My] = 0;
while(!me.empty()) {
curx = me.front().F;
cury = me.front().S;
me.pop();
for(i = 0; i < 4; i++) {
movexx = movex[i] + curx;
moveyy = movey[i] + cury;
if(check(movexx, moveyy) && maps[movexx][moveyy] == 'D') {
while(!me.empty())
me.pop();
return true;
}
if(check(movexx, moveyy) && (maps[movexx][moveyy] == 'G' || maps[movexx][moveyy] == 'D') && meStep[curx][cury] + 1 < s * (beeStep[movexx][moveyy] - mid) && meStep[movexx][moveyy] == 1e9) {
meStep[movexx][moveyy] = meStep[curx][cury] + 1;
me.push(mp(movexx, moveyy));
}
}
}
return false;
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio;
int i, j, l, r, curx, cury, curstep, movexx, moveyy, mid;
cin >> n >> s;
memset(beeStep, -1, sizeof(beeStep));
for(i = 0; i < n; i++) {
cin >> maps[i];
for(j = 0; j < n; j++) {
if(maps[i][j] == 'H') {
bee.push(mp(i, j));
beeStep[i][j] = 0;
}
if(maps[i][j] == 'M') {
Mx = i; My = j;
}
if(maps[i][j] == 'D') {
Dx = i; Dy = j;
}
}
}
while(!bee.empty()) {
curx = bee.front().F;
cury = bee.front().S;
bee.pop();
for(i = 0; i < 4; i++) {
movexx = movex[i] + curx;
moveyy = movey[i] + cury;
if((check(movexx, moveyy) && maps[movexx][moveyy] == 'G' || maps[movexx][moveyy] == 'M') && beeStep[movexx][moveyy] == -1) {
beeStep[movexx][moveyy] = beeStep[curx][cury] + 1;
bee.push(mp(movexx, moveyy));
}
}
}
if(!can(0)) {
cout << "-1\n";
return 0;
}
l = 0; r = n * n;
while(l != r) {
mid = (l + r + 1) / 2;
if(can(mid)) l = mid;
else r = mid - 1;
}
cout << l << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |