제출 #104093

#제출 시각아이디문제언어결과실행 시간메모리
104093ErkhemkhuuMecho (IOI09_mecho)C++17
100 / 100
299 ms6392 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}; 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) 메시지

mecho.cpp: In function 'bool can(int)':
mecho.cpp:19:18: warning: unused variable 'curstep' [-Wunused-variable]
  int curx, cury, curstep, i, j, i1, movexx, moveyy;
                  ^~~~~~~
mecho.cpp:19:33: warning: unused variable 'i1' [-Wunused-variable]
  int curx, cury, curstep, i, j, i1, movexx, moveyy;
                                 ^~
mecho.cpp: In function 'int main()':
mecho.cpp:48:27: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
  ios_base::sync_with_stdio;
                           ^
mecho.cpp:48:27: warning: statement has no effect [-Wunused-value]
mecho.cpp:74:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if((check(movexx, moveyy) && maps[movexx][moveyy] == 'G' || maps[movexx][moveyy] == 'M') && beeStep[movexx][moveyy] == -1) {
        ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:49:30: warning: unused variable 'curstep' [-Wunused-variable]
  int i, j, l, r, curx, cury, curstep, movexx, moveyy, mid;
                              ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...