Submission #155785

#TimeUsernameProblemLanguageResultExecution timeMemory
155785m1sch3fMecho (IOI09_mecho)C++17
100 / 100
795 ms4404 KiB
#include <bits/stdc++.h> using namespace std; // types - only for stuff used a lot using ll = long long; #define vv vector #define Pp pair // IO #define get(x) scanf("%d",&x) #define getl(x) scanf("%lld",&x); // Operations #define pb push_back #define pob pop_back #define sz(a) int(a.size()) #define re(a,b) a=max(a,b) // relax #define ri(a,b) a=min(a,b) // relaxi // Debugging #ifndef LOCAL #define cerr if (0) cerr #else #define cerr cout #endif #define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; } #define printv(vec) {for (int _ : vec) cerr<<_<<" "; cerr<<endl;} const int mod = 1e9+7, oo = 1e9; const ll loo = 1e18; // Functions ll modpow(ll a, ll b) { ll ans = 1; // faster modpow than recursive for (; b; b/=2,a=a*a%mod) if (b&1) ans = (ans*a)%mod; return ans; } ll gcd(ll a, ll b) { while (a) b%=a,swap(a,b); return b; } #define bitcount __builtin_popcountll #define f(i,a,b) for (int i = a; i < b; i++) #define fr(i,a,b) for (int i = b-1; i >= a; i--) /* ALRIGHT HACKERS, THIS IS WHERE THE ACTUAL CODE BEGINS */ const bool DEBUG = 1; using pii = pair<int,int>; #define IN(i,a,b) (a<=i&&i<=b) const int N = 1000; int n,s; vector<pii> bees; bool wall[N][N],visR[N][N],visB[N][N]; pii st, fin; int di[] = {1,-1,0,0}; int dj[] = {0,0,1,-1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL if (DEBUG) freopen("input.txt", "r", stdin); if (DEBUG) freopen("output.txt", "w", stdout); clock_t start = clock(); #endif cin>>n>>s; f(i,0,n) f(j,0,n) wall[i][j] = 0; f(i,0,n) f(j,0,n) { char c; cin>>c; if (c == 'T') wall[i][j] = 1; else if (c == 'M') st = {i,j}; else if (c == 'D') fin = {i,j}; else if (c == 'H') bees.pb({i,j}); } int lo = 0, hi = N*N*2; auto valid = [&](int i, int j) { return IN(i,0,n-1) && IN(j,0,n-1) && !wall[i][j] && !visR[i][j]; }; auto fu = [&](int T) { f(i,0,n) f(j,0,n) visB[i][j] = visR[i][j] = 0; vector<pii> bear, bee; bear.pb(st); visB[st.first][st.second] = 1; for (pii b : bees) { bee.pb(b); visR[b.first][b.second] = 1; } while (bear.size()||bee.size()) { // bear gets to move first if (T--<=0) { // eat for T rounds f(_,0,s) { vector<pii> nxt; for (pii pp : bear) { int i = pp.first, j = pp.second; if (visR[i][j]) continue; f(k,0,4) { int ni = i+di[k], nj = j+dj[k]; if (valid(ni,nj) && !visB[ni][nj]) { visB[ni][nj] = 1; nxt.pb({ni,nj}); } } } bear = nxt; } } // then bee move vector<pii> nxt; for (pii pp : bee) { int i = pp.first, j = pp.second; f(k,0,4) { int ni = i+di[k], nj = j+dj[k]; if (valid(ni,nj) && pii(ni,nj) != fin) { visR[ni][nj] = 1; nxt.pb({ni,nj}); } } } bee = nxt; } return visB[fin.first][fin.second]; }; while (lo<=hi) { int mid = lo+hi>>1; if (fu(mid)) lo = mid+1; else hi = mid-1; } cout << hi << endl; #ifdef LOCAL cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl; #endif return 0; }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:147:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lo+hi>>1;
             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...