제출 #935004

#제출 시각아이디문제언어결과실행 시간메모리
935004May27_thMecho (IOI09_mecho)C++17
84 / 100
136 ms7000 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; void World_Final(); void Solve(); int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(taskname".in", "r")) { freopen(taskname".in", "r", stdin); freopen(taskname".out", "w", stdout); } World_Final(); } void World_Final(){ int Tests = 1; //cin >> Tests; while (Tests --) { Solve(); } } const int MAXN = 805; int N, S, bee[MAXN][MAXN], bear[MAXN][MAXN]; char G[MAXN][MAXN]; int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; pair<int, int> st, en; bool query(int rest){ memset(bear, -1, sizeof(bear)); queue<pair<int, int>> q; q.push(st); bear[st.first][st.second] = 0; while (!q.empty()) { int u, v; tie(u, v) = q.front(); //cout << u << " " << v << "\n"; q.pop(); for (int i = 0; i < 4; i ++) { int nu = u + dx[i]; int nv = v + dy[i]; if (nu >= 1 && nu <= N && nv >= 1 && nv <= N) { if (G[nu][nv] == 'G' && bear[nu][nv] == -1) { int t = (bear[u][v] + 1)/S; if (t < bee[nu][nv] - rest) { bear[nu][nv] = bear[u][v] + 1; q.push(make_pair(nu, nv)); } } if (G[nu][nv] == 'D' && bear[nu][nv] == -1) { bear[nu][nv] = bear[u][v] + 1; q.push(make_pair(nu, nv)); } } } } return bear[en.first][en.second] != -1; } void Solve(){ cin >> N >> S; for (int i = 1; i <= N; i ++) { for (int j = 1; j <= N; j ++) { cin >> G[i][j]; } } memset(bee, -1, sizeof(bee)); queue<pair<int, int>> q; for (int i = 1; i <= N; i ++) { for (int j = 1; j <= N; j ++) { if (G[i][j] == 'H') { bee[i][j] = 0; q.push(make_pair(i, j)); } if (G[i][j] == 'M') st = make_pair(i, j); if (G[i][j] == 'D') en = make_pair(i, j); } } while (!q.empty()) { int u, v; tie(u, v) = q.front(); q.pop(); for (int i = 0; i < 4; i ++) { int nu = u + dx[i]; int nv = v + dy[i]; if (nu >= 1 && nu <= N && nv >= 1 && nv <= N) { if ((G[nu][nv] == 'G' || G[nu][nv] == 'M') && bee[nu][nv] == -1) { bee[nu][nv] = bee[u][v] + 1; q.push(make_pair(nu, nv)); } } } } int l = 0, h = 1e9; while (l <= h) { int mid = (l + h) / 2; //cout << mid << "\n"; if (query(mid)) l = mid + 1; else h = mid - 1; } cout << h; }

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

mecho.cpp: In function 'int main()':
mecho.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen(taskname".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...