Submission #718788

#TimeUsernameProblemLanguageResultExecution timeMemory
718788NintsiChkhaidzeMecho (IOI09_mecho)C++14
100 / 100
175 ms8080 KiB
#include <bits/stdc++.h> #define pb push_back #define ll long long #define f first #define s second #define int ll using namespace std; const int inf = 1e18,N = 805; char a[N][N]; int dis[N][N],xm,ym,n,S; bool fix[N][N]; vector <pair<int,int> > neighbours = {{0,1}, {0,-1},{1,0}, {-1,0}}; bool check(int t){ if (dis[xm][ym] <= t*S) return 0; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) fix[i][j]=0; queue <pair <int,pair<int,int> > > q; while (q.size()) q.pop(); q.push({t*S,{xm,ym}}); fix[xm][ym] = 1; while (q.size()){ int T = q.front().f,x = q.front().s.f,y = q.front().s.s; q.pop(); if (a[x][y] == 'D') return 1; for (auto [dx,dy]: neighbours){ int X = x+dx,Y = y+dy; if (X < 1 || Y < 1 || X > n || Y > n || fix[X][Y]) continue; if (a[X][Y] == 'T' || a[X][Y] == 'H') continue; if (dis[X][Y] <= T + 1) continue; fix[X][Y] = 1; q.push({T+1,{X,Y}}); } } return 0; } signed main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); cin>>n>>S; queue <pair<int,pair<int,int> > > q; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++){ cin >> a[i][j]; dis[i][j] = inf; if (a[i][j] == 'H') dis[i][j] = 0,q.push({0,{i,j}}),fix[i][j] = 1; if (a[i][j] == 'M') xm = i,ym = j; } while (q.size()){ int d = q.front().f,x = q.front().s.f,y = q.front().s.s; q.pop(); for (auto [dx,dy]: neighbours){ int X = x+dx,Y = y+dy; if (X < 1 || Y < 1 || X > n || Y > n) continue; if (fix[X][Y] || (a[X][Y] == 'T' || a[X][Y] == 'D')) continue; dis[X][Y] = d + S; fix[X][Y] = 1; q.push({d+S,{X,Y}}); } } int l = 0,r = 1e9,ans=-1; while (l <= r){ int mid = (l + r)>>1; if (check(mid)) { ans = mid,l = mid + 1; }else{ r = mid - 1; } } cout<<ans; }

Compilation message (stderr)

mecho.cpp: In function 'bool check(long long int)':
mecho.cpp:31:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |         for (auto [dx,dy]: neighbours){
      |                   ^
mecho.cpp: In function 'int main()':
mecho.cpp:58:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   58 |         for (auto [dx,dy]: neighbours){
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...