Submission #724833

#TimeUsernameProblemLanguageResultExecution timeMemory
724833chanhchuong123Mecho (IOI09_mecho)C++14
89 / 100
191 ms6224 KiB
#include <bits/stdc++.h> using namespace std; #define task "" #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(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 MAX = 800; int n, S; int xM, yM; int xD, yD; char a[MAX][MAX]; int bee[MAX][MAX]; int bear[MAX][MAX]; queue<pair<int, int>> q; bool ok(int add) { memset(bear, -1, sizeof bear); q.push({xM, yM}); bear[xM][yM] = 0; 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] == 'M' || a[x][y] == 'G' || a[x][y] == 'D') { int candidate = bear[u][v] + 1; if (add + candidate / S < bee[x][y]) { if (bear[x][y] == -1) { q.push({x, y}); bear[x][y] = candidate; } } } } } for (int i = 0; i < 4; ++i) { int x = xD + dx[i], y = yD + dy[i]; if (x < 0 || x >= n) continue; if (y < 0 || y >= n) continue; if (bear[x][y] == -1) continue; if (a[x][y] == 'T' || a[x][y] == 'H') continue; if (add + bear[x][y] / S < bee[x][y]) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> S; memset(bee, -1, sizeof bee); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> a[i][j]; if (a[i][j] == 'H') { bee[i][j] = 0; q.push({i, j}); } if (a[i][j] == 'D') { xD = i, yD = j; } if (a[i][j] == 'M') { xM = i, yM = 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') { if (bee[x][y] == -1) { q.push({x, y}); bee[x][y] = bee[u][v] + 1; } } } } // int l = -1, r = 1e9; while (r - l > 1) { int mid = l + r >> 1; if (ok(mid)) l = mid; else r = mid; } cout << l; return 0; }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:112:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  112 |         int mid = l + r >> 1;
      |                   ~~^~~
mecho.cpp:70:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:71:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...