Submission #394053

#TimeUsernameProblemLanguageResultExecution timeMemory
394053Valera_GrinenkoMecho (IOI09_mecho)C++17
38 / 100
229 ms4920 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <set> #include <stack> #include <map> #include <unordered_map> #include <iomanip> #include <cmath> #include <queue> #include <bitset> #include <numeric> #include <array> #include <cstring> #include <random> #include <chrono> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef long long ll; typedef long double ld; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 803; char d[N][N]; int b[N][N]; int sx = 0, sy = 0, fx = 0, fy = 0; int n, s; int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; char check(int tt) { vector<vector<char> > u(n, vector<char>(n)); queue<pair<int, pair<int, int> > > q; u[sx][sy] = true; q.push(mp(0, mp(sx, sy))); while(!q.empty()) { auto x = q.front(); q.pop(); int xx = x.se.fi, yy = x.se.se, cd = x.fi; if(xx == fx && yy == fy) return true; for(int mv = 0; mv < 4; mv++) { int i = xx + dx[mv], j = yy + dy[mv]; if(i >= 0 && i < n && j >= 0 && j < n && !u[i][j] && d[i][j] != 'T') { if(i == fx && j == fy) { return true; } int cl = cd / s + tt; if(b[i][j] > cl) { q.push(mp(cd + 1, mp(i, j))); u[i][j] = true; } } } } return false; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; queue<pair<int, int> > bee; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { b[i][j] = -1; cin >> d[i][j]; if(d[i][j] == 'H') { bee.push(mp(i, j)); b[i][j] = 0; } } while(!bee.empty()) { auto x = bee.front(); bee.pop(); for(int mv = 0; mv < 4; mv++) { int i = x.fi + dx[mv], j = x.se + dy[mv]; if(i >= 0 && i < n && j >= 0 && j < n && b[i][j] == -1 && d[i][j] != 'T') { b[i][j] = b[x.fi][x.se] + 1; bee.push(mp(i, j)); } } } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(d[i][j] == 'D') fx = i, fy = j; if(d[i][j] == 'M') sx = i, sy = j; } } if(!check(0)) { cout << -1; return 0; } int l = 0, r = n * n; while(l < r) { int m = (l + r + 1) / 2; if(check(m)) l = m; else r = m - 1; } cout << l; return 0; } /* */

Compilation message (stderr)

mecho.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...