제출 #730138

#제출 시각아이디문제언어결과실행 시간메모리
730138CutSandstoneMecho (IOI09_mecho)C++17
21 / 100
369 ms22100 KiB
#include <bits/stdc++.h> #define f first #define s second using ll = long long; using namespace std; const int inf = 1<<30; int bees[800][800]; bool go[800][800]; int bfs[640000][3]; int p1, p2, len; int ra, rb, rc; pair<int, int> st, en; pair<int, int> d4[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; int N, S; void push(int a, int b, int c){ bfs[p2][0] = a; bfs[p2][1] = b; bfs[p2][2] = c; p2++; if(p2 == 640000) p1 = 0; len++; } void poll(){ ra = bfs[p1][0]; rb = bfs[p1][1]; rc = bfs[p1][2]; p1++; if(p1 == 640000) p1 = 0; len--; } bool works(int t){ p1 = p2 = len = 0; push(st.f, st.s, 0); while(len) { poll(); for(pair<int, int> a: d4) { vector<int> next = {ra+a.f, rb+a.s, rc+1}; if(next[0] >= 0 && next[0] < N && next[1] >= 0 && next[1] < N && go[next[0]][next[1]] && next[2]/S < bees[next[0]][next[1]]-t) { if(next[0] == en.f && next[1] == en.s) return 1; push(next[0], next[1], next[2]); } } } return 0; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); p1 = p2 = len = 0; cin >> N >> S; for(int i = 0; i<N; i++) for(int j = 0; j<N; j++) bees[i][j] = inf; for(int i = 0; i<N; i++) { string c; cin >> c; for(int j = 0; j<N; j++) { go[i][j] = c[j] != 'T'; if(c[j] == 'M') st = {i, j}; if(c[j] == 'D') en = {i, j}; if(c[j] == 'H') { push(i, j, 0); bees[i][j] = 0; } } } while(len) { poll(); int c = bees[ra][rb]; for(pair<int, int> a: d4) { vector<int> next = {ra+a.f, rb+a.s}; if(next[0] >= 0 && next[1] >= 0 && next[0] < N && next[1] < N && go[next[0]][next[1]] && bees[next[0]][next[1]] == inf && (next[0] != en.f || next[1] != en.s)) { bees[next[0]][next[1]] = c+1; push(next[0], next[1], 0); } } } int lo = -1, hi = bees[st.f][st.s]+1; while (lo < hi) { int mid = lo + (hi - lo + 1) / 2; if (works(mid)) lo = mid; else hi = mid - 1; } cout << lo; }
#Verdict Execution timeMemoryGrader output
Fetching results...