Submission #499619

#TimeUsernameProblemLanguageResultExecution timeMemory
499619_AnKahngMecho (IOI09_mecho)C++14
15 / 100
147 ms4612 KiB
#include<bits/stdc++.h> #define fi first #define sc second #define fr(i,a,b) for(int i=a;i<=b;i++) #define fo(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int H[] = {-1,-1,1,1}; const int M = 805; int n,s,f[M][M]; bool cx[M][M]; pair<int,int> st,fn; string a[M]; struct dota{ int x,y,d; }; void BFS_hive(){ queue<dota> q; memset(cx,false,sizeof(cx)); fo(i,1,n) fo(j,1,n) { if(a[i][j] != 'T') cx[i][j] = true; if(a[i][j] == 'H') q.push({i,j,0}), f[i][j] = 0, cx[i][j] = false; } while(!q.empty()){ int x = q.front().x, y = q.front().y, d = q.front().d; q.pop(); f[x][y] = d; int xi,yi; fo(k,0,3){ if(k % 2) xi = x + H[k], yi = y; else xi = x, yi = y + H[k]; if(cx[xi][yi]) q.push({xi,yi,d+1}), cx[xi][yi] = false; } } } bool check(int t){ queue<dota> q; memset(cx,false,sizeof(cx)); fo(i,1,n) fo(j,1,n) if(a[i][j] != 'T') cx[i][j] = true; q.push({st.fi,st.sc,0}); cx[st.fi][st.sc] = false; while(!q.empty()){ int x = q.front().x, y = q.front().y, d = q.front().d; q.pop(); if(x == fn.fi && y == fn.sc) return true; int xi,yi; fo(k,0,3){ if(k % 2) xi = x + H[k], yi = y; else xi = x, yi = y + H[k]; if(cx[xi][yi] && (d + 1) / s < f[xi][yi] - t) q.push({xi,yi,d+1}), cx[xi][yi] = false; } } return false; } int main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> s; fo(i,1,n) cin >> a[i], a[i] = "*" + a[i]; fo(i,1,n) fo(j,1,n) if(a[i][j] == 'M') st = {i,j}; else if(a[i][j] == 'D') fn = {i,j}; BFS_hive(); //fo(i,1,n) fo(j,1,n) cout << f[i][j]<<" \n"[j == n]; int l = 0, r = n, mid,res; while(l <= r){ mid = (l + r) / 2; if(check(mid)) l = mid+1, res = mid; else r = mid-1; } cout << res; }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:77:13: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |     cout << res;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...