# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
335552 | CursedCode | Mecho (IOI09_mecho) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<mecho.h>
#include <bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
using namespace std;
int n, s;
pair<int, int> start, home;
int T, H;
int occ_time[805][805];
bool vis[805][805];
bool tree[805][805];
pair<int, int > Q[1000000];
int movex[] = {0, 0, -1, 1};
int movey[] = {-1, 1, 0, 0};
bool check(pair<int, int> v){
if(v.x >= 0 && v.x < n && v.y >= 0 && v.y < n && !tree[v.x][v.y] && !vis[v.x][v.y]) return 1;
return 0;
}
void init_bfs(){
pair<int, int> u, v;
while(H < T){
u = Q[H++];
if(u == home) continue;
//cout << u.x << ' ' << u.y << ' ' << occ_time[u.x][u.y] << endl;
for(int i = 0; i < 4; i++){
v = mp(u.x + movex[i], u.y + movey[i]);
if(!check(v)) continue;
occ_time[v.x][v.y] = occ_time[u.x][u.y] + s;
vis[v.x][v.y] = 1;
Q[T++] = v;
}
}
}
int dist[805][805];
bool solve(int st){
memset(vis, 0, sizeof(vis));
H = T = 0;
pair<int, int> u, v;
dist[start.x][start.y] = st;
Q[T++] = start;
while(H < T){
u = Q[H++];
if(u == home) return 1;
if(dist[u.x][u.y] >= occ_time[u.x][u.y]) continue;
for(int i = 0; i < 4; i++){
v = mp(u.x + movex[i], u.y + movey[i]);
if(!check(v)) continue;
dist[v.x][v.y] = dist[u.x][u.y] + 1;
vis[v.x][v.y] = 1;
Q[T++] = v;
}
}
return 0;
}
int search(){
int l = 0, r = 800 * 800 + 1;
int res = -1;
while(l <= r){
int mid = (l + r) / 2;
//cout << mid << endl;
if(solve(mid * s)){
l = mid + 1;
res = max(res, mid);
}
else r = mid - 1;
}
return res;
}