제출 #491455

#제출 시각아이디문제언어결과실행 시간메모리
491455XIIMecho (IOI09_mecho)C++17
100 / 100
169 ms10704 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second #define mp make_pair #define eb emplace_back #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORU(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define IOS cin.tie(0)->sync_with_stdio(false); #define PROB "IOI09_mecho" void Fi(){ if(fopen(PROB".inp", "r")){ freopen(PROB".inp", "r", stdin); freopen(PROB".out", "w", stdout); } } const int INF = 1e9; const int N = 800 + 1; int n, spd; int a[N][N]; using pi = pair<int, int>; pi S, E; queue<pi> qe; int d[N][N]; const int dx[] = {0, 0, -1, +1}; const int dy[] = {-1, +1, 0, 0}; void bfsBee(){ while(!qe.empty()){ auto [x, y] = qe.front(); qe.pop(); FOR(direc, 0, 4){ int i = x + dx[direc]; int j = y + dy[direc]; if(i < 1 || n < i || j < 1 || n < j) continue; if(a[i][j] == 1 && d[i][j] == -1){ d[i][j] = d[x][y] + 1; qe.emplace(i, j); } } } } pi D[N][N]; bool bfsMecho(const int &T){ FORU(i, 1, n) FORU(j, 1, n) D[i][j] = {INF, INF}; qe.emplace(S); D[S.fi][S.se] = {T, 0}; while(!qe.empty()){ auto [x, y] = qe.front(); qe.pop(); // cout << x << " " << y << " " << D[x][y].fi << " " << D[x][y].se << "\n"; FOR(direc, 0, 4){ int i = x + dx[direc]; int j = y + dy[direc]; if(i < 1 || n < i || j < 1 || n < j) continue; if(a[i][j] && D[i][j].fi == INF){ D[i][j] = D[x][y]; if(++D[i][j].se >= spd){ ++D[i][j].fi; D[i][j].se = 0; } if(a[i][j] == 2){ while(!qe.empty()) qe.pop(); return true; } if(D[i][j].fi < d[i][j]){ qe.emplace(i, j); } } } } return false; } int main(){ IOS; Fi(); cin >> n >> spd; memset(d, -1, sizeof(d)); FORU(i, 1, n){ string s; cin >> s; FORU(j, 1, n){ switch(s[j - 1]){ case 'T': a[i][j] = 0; break; case 'G': a[i][j] = 1; break; case 'M': a[i][j] = 1; S = {i, j}; break; case 'D': a[i][j] = 2; E = {i, j}; break; case 'H': a[i][j] = 0; qe.emplace(i, j); d[i][j] = 0; break; } } } bfsBee(); int l = 0, r = d[S.fi][S.se] - 1, ans = -1; while(l <= r){ int m = (l + r) / 2; if(bfsMecho(m)) l = m + 1, ans = m; else r = m - 1; } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

mecho.cpp: In function 'void Fi()':
mecho.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...