제출 #661299

#제출 시각아이디문제언어결과실행 시간메모리
661299chanhchuong123Mecho (IOI09_mecho)C++14
89 / 100
196 ms6952 KiB
#include <bits/stdc++.h> using namespace std; #define task "C" #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int dx[] = {-1, 0, 0, +1}; const int dy[] = {0, -1, +1, 0}; const int N = 808; int n, S; char a[N][N]; int bee[N][N]; int bear[N][N]; pair<int, int> st, en; int ADD; bool canMove(int dist, int i, int j) { if (bee[i][j] == -1) return true; return dist / S + ADD < bee[i][j]; } bool check() { memset(bear, -1, sizeof(bear)); queue<pair<int, int>> q; bear[st.fi][st.se] = 0; q.push(st); while (q.size()) { int u = q.front().fi; int v = q.front().se; q.pop(); for (int i = 0; i < 4; i++) { int x = u + dx[i], y = v + dy[i]; if (x < 0 || x >= n) continue; if (y < 0 || y >= n) continue; if (a[x][y] == 'T') continue; if (bear[x][y] == -1 && canMove(bear[u][v] + 1, x, y)) { bear[x][y] = bear[u][v] + 1; q.push(make_pair(x, y)); } } } int u = en.fi, v = en.se; for (int i = 0; i < 4; i++) { int x = u + dx[i], y = v + dy[i]; if (x < 0 || x >= n) continue; if (y < 0 || y >= n) continue; if (a[x][y] == 'T') continue; if (bear[x][y] == -1) continue; if (canMove(bear[x][y], x, y)) return true; } return false; } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n >> S; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; if (a[i][j] == 'M') st = make_pair(i, j); if (a[i][j] == 'D') en = make_pair(i, j); } } memset(bee, -1, sizeof(bee)); queue<pair<int, int>> q; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i][j] == 'H') { bee[i][j] = 0; q.push(make_pair(i, j)); } } } while (q.size()) { int u = q.front().fi; int v = q.front().se; q.pop(); for (int i = 0; i < 4; i++) { int x = u + dx[i], y = v + dy[i]; if (x < 0 || x >= n) continue; if (y < 0 || y >= n) continue; if (a[x][y] == 'T' || a[x][y] == 'D') continue; if (bee[x][y] == -1) { q.push(make_pair(x, y)); bee[x][y] = bee[u][v] + 1; } } } ADD = 0; if (check() == false) { cout << "-1"; return 0; } int l = 0, r = n * n + 1; while (r - l > 1) { int mid = l + r >> 1; ADD = mid; if (check()) l = mid; else r = mid; } cout << l; }

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

mecho.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main() {
      | ^~~~
mecho.cpp: In function 'int main()':
mecho.cpp:111:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  111 |     int mid = l + r >> 1;
      |               ~~^~~
mecho.cpp:67:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:68:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...