Submission #104092

#TimeUsernameProblemLanguageResultExecution timeMemory
104092ErkhemkhuuMecho (IOI09_mecho)C++17
12 / 100
170 ms7688 KiB
#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}; string maps[805]; int beeStep[805][805], meStep[805][805], n, Mx, My, s, Dx, Dy; queue <pair <int, int> > bee, me; inline bool can(int mid) { if(mid >= beeStep[Mx][My]) return false; int curx, cury, curstep, i, j, i1, movexx, moveyy; me.push({Mx, My}); for(i = 0; i <= n; i++) for(j = 0; j <= n; j++) meStep[i][j] = INT_MAX; 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(maps[movexx][moveyy] == 'D') { while(!me.empty()) me.pop(); return true; } if((maps[movexx][moveyy] == 'G' || maps[movexx][moveyy] == 'D') && meStep[curx][cury] + 1 < s * (beeStep[movexx][moveyy] - mid) && meStep[movexx][moveyy] == INT_MAX) { 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((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 = 1e9; while(l != r) { mid = (l + r + 1) / 2; if(can(mid)) l = mid; else r = mid - 1; } cout << l << "\n"; return 0; }

Compilation message (stderr)

mecho.cpp: In function 'bool can(int)':
mecho.cpp:16:18: warning: unused variable 'curstep' [-Wunused-variable]
  int curx, cury, curstep, i, j, i1, movexx, moveyy;
                  ^~~~~~~
mecho.cpp:16:33: warning: unused variable 'i1' [-Wunused-variable]
  int curx, cury, curstep, i, j, i1, movexx, moveyy;
                                 ^~
mecho.cpp: In function 'int main()':
mecho.cpp:45:27: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
  ios_base::sync_with_stdio;
                           ^
mecho.cpp:45:27: warning: statement has no effect [-Wunused-value]
mecho.cpp:46:30: warning: unused variable 'curstep' [-Wunused-variable]
  int i, j, l, r, curx, cury, curstep, movexx, moveyy, mid;
                              ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...