Submission #472735

#TimeUsernameProblemLanguageResultExecution timeMemory
472735hackerbhaiyaMecho (IOI09_mecho)C++17
95 / 100
561 ms11304 KiB
#include<bits/stdc++.h> // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") // #pragma GCC optimization("unroll-loops") // #pragma GCC optimize("unroll-loops") // #pragma GCC optimize("fast-math") // #pragma GCC optimize("no-stack-protector") // #define ll __int128 #define ll long long // #define ll int #define f(i,a,b) for(int i=a;i<b;i++) #define mod 1000000007 // #define mod 998244353 #define mp make_pair #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define ff first #define ss second #define rf(i,a,b) for(int i=a;i>=b;i--) #define sc(a) scanf("%lld",&a) #define pf printf #define sz(a) (int)(a.size()) #define psf push_front #define ppf pop_front #define ppb pop_back #define pb push_back #define pq priority_queue #define all(s) s.begin(),s.end() #define sp(a) setprecision(a) #define rz resize #define ld long double #define inf (ll)1e18 #define ub upper_bound #define lb lower_bound #define bs binary_search #define eb emplace_back const double pi = acos(-1); ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;} // ll binpow(ll a, ll b, ll md){ll res=1;a%=mod;while(b!=0){if(b&1)res*=a,res%=md;a*=a,a%=md;b>>=1;}return res%md;} using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("xortransform.in","r",stdin); // freopen("xortransform.out","w",stdout); // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int z=1; // cin>>z; f(i,1,z+1) { //cout<<"Case #"<<i<<": "; ll n,d,sx,sy,fx,fy; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; cin>>n>>d; vector<string> s(n); f(i,0,n) cin>>s[i]; ll l=0,r=n*n+1; queue<vector<ll> > q; vector<vector<ll> > dis(n,vector<ll> (n,inf)); f(i,0,n) { f(j,0,n) { if(s[i][j]=='H') q.push({i,j}),dis[i][j]=0; else if(s[i][j]=='M') sx=i,sy=j; else if(s[i][j]=='D') fx=i,fy=j; } } while(!q.empty()) { auto temp=q.front(); q.pop(); ll x=temp[0],y=temp[1]; f(i,0,4) { ll xx=x+dx[i],yy=y+dy[i]; if(xx>=0 && yy>=0 && xx<n && yy<n && s[xx][yy]!='T' && dis[xx][yy]>d+dis[x][y]) dis[xx][yy]=d+dis[x][y],q.push({xx,yy}); } } while(l<=r) { ll mid=(l+r)/2; queue<vector<ll> > q; vector<vector<ll> > dis2(n,vector<ll> (n,inf)); if(dis[sx][sy]>mid*d) q.push({sx,sy}); dis2[sx][sy]=mid*d; while(!q.empty()) { auto temp=q.front(); q.pop(); ll x=temp[0],y=temp[1]; if(x==fx && y==fy) break; f(i,0,4) { ll xx=x+dx[i],yy=y+dy[i]; if(xx>=0 && yy>=0 && xx<n && yy<n && s[xx][yy]!='T' && dis2[xx][yy]>1+dis2[x][y]) { if((xx==fx && yy==fy) || (1+dis2[x][y]<dis[xx][yy])) dis2[xx][yy]=1+dis2[x][y],q.push({xx,yy}); } } } if(dis2[fx][fy]<inf) l=mid+1; else r=mid-1; } cout<<r<<"\n"; } }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:116:27: warning: 'fy' may be used uninitialized in this function [-Wmaybe-uninitialized]
  116 |             if(dis2[fx][fy]<inf)
      |                           ^
mecho.cpp:116:23: warning: 'fx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  116 |             if(dis2[fx][fy]<inf)
      |                       ^
mecho.cpp:96:26: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |             if(dis[sx][sy]>mid*d)
      |                          ^
mecho.cpp:96:22: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |             if(dis[sx][sy]>mid*d)
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...