| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 155784 | m1sch3f | Mecho (IOI09_mecho) | C++17 | 289 ms | 4440 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 800;
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<<2|1;
	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) {
		int t = 0;
		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()) {
			// bear gets to move first
			if (t++>=T) {
				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;
				}
			}
			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)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
