Submission #789653

#TimeUsernameProblemLanguageResultExecution timeMemory
789653phongcdMecho (IOI09_mecho)C++14
0 / 100
5 ms404 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define ii pair <int, int> #define ill pair <ll, ll> #define fi first #define se second #define all(x) x.begin(), x.end() #define file "test" using namespace std; const ll N = 8e2 + 2; const ll MOD = 1e9; const ll INF = 1e18; const ll base = 311; const int BLOCK_SIZE = 2000; int n, s; ii start, target, d[N][N]; char a[N][N]; int mtime[N][N]; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; void addstep(ii &a) { a.se += 1; if (a.se > s) a.fi ++, a.se = 1; } bool cmp(ii a, ii b) { if (a.fi != b.fi) return a.fi < b.fi; return a.se < b.se; } bool check(int x) { for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++) d[i][j] = {2e9, 0}; queue <ii> h; h.push(start); d[start.fi][start.se] = {x + 1, 0}; while (!h.empty()) { auto [x, y] = h.front(); h.pop(); ii res = d[x][y]; addstep(res); for (int j = 0; j <= 3; j ++) { int u = x + dx[j]; int v = y + dy[j]; if (a[u][v] == 'G' && res.fi <= mtime[u][v] && !cmp(d[u][v], res)) { h.push({u, v}); d[u][v] = res; } } } return d[target.fi][target.se].fi != 2e9; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen(file".inp","r",stdin); freopen(file".out","w",stdout); #endif cin >> n >> s; queue <ii> bee; for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++) { cin >> a[i][j]; mtime[i][j] = 2e9; if (a[i][j] == 'H') bee.push({i, j}), mtime[i][j] = 0; if (a[i][j] == 'M') a[i][j] = 'G', start = {i, j}; if (a[i][j] == 'D') a[i][j] = 'G', target = {i, j}; } while (!bee.empty()) { auto [x, y] = bee.front(); bee.pop(); int res = mtime[x][y] + 1; for (int j = 0; j <= 3; j ++) { int u = x + dx[j]; int v = y + dy[j]; if (a[u][v] == 'G' && mtime[u][v] > res) { bee.push({u, v}); mtime[u][v] = res; } } } int l = 1, r = 2e3; while (l < r) { int mid = l + (r - l + 1) / 2; if (check(mid)) l = mid; else r = mid - 1; } cout << (check(l) ? l : -1); } /* /\_/\ zzZ (= -_-) / >u >u */

Compilation message (stderr)

mecho.cpp: In function 'bool check(int)':
mecho.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |         auto [x, y] = h.front(); h.pop();
      |              ^
mecho.cpp: In function 'int main()':
mecho.cpp:84:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   84 |         auto [x, y] = bee.front(); bee.pop();
      |              ^
mecho.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:63:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...