Submission #155784

# Submission time Handle Problem Language Result Execution time Memory
155784 2019-09-30T14:24:13 Z m1sch3f Mecho (IOI09_mecho) C++17
76 / 100
289 ms 4440 KB

#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

mecho.cpp: In function 'int main()':
mecho.cpp:145:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = lo+hi>>1;
             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1656 KB Output is correct
2 Correct 11 ms 1528 KB Output is correct
3 Correct 11 ms 1656 KB Output is correct
4 Correct 11 ms 1528 KB Output is correct
5 Correct 12 ms 1656 KB Output is correct
6 Correct 11 ms 1656 KB Output is correct
7 Correct 249 ms 3384 KB Output is correct
8 Correct 11 ms 1656 KB Output is correct
9 Correct 10 ms 1656 KB Output is correct
10 Correct 11 ms 1528 KB Output is correct
11 Correct 11 ms 1656 KB Output is correct
12 Correct 12 ms 1656 KB Output is correct
13 Correct 13 ms 1656 KB Output is correct
14 Correct 13 ms 1656 KB Output is correct
15 Correct 12 ms 1656 KB Output is correct
16 Correct 11 ms 1656 KB Output is correct
17 Correct 11 ms 1656 KB Output is correct
18 Correct 11 ms 1660 KB Output is correct
19 Correct 11 ms 1656 KB Output is correct
20 Correct 12 ms 1656 KB Output is correct
21 Correct 12 ms 1656 KB Output is correct
22 Correct 11 ms 1656 KB Output is correct
23 Correct 12 ms 1656 KB Output is correct
24 Correct 12 ms 1656 KB Output is correct
25 Correct 12 ms 1656 KB Output is correct
26 Correct 12 ms 1660 KB Output is correct
27 Correct 13 ms 1656 KB Output is correct
28 Correct 13 ms 1660 KB Output is correct
29 Correct 14 ms 1656 KB Output is correct
30 Correct 14 ms 1656 KB Output is correct
31 Correct 14 ms 1656 KB Output is correct
32 Correct 14 ms 1656 KB Output is correct
33 Incorrect 63 ms 2040 KB Output isn't correct
34 Incorrect 63 ms 2140 KB Output isn't correct
35 Correct 48 ms 2040 KB Output is correct
36 Incorrect 77 ms 2104 KB Output isn't correct
37 Incorrect 77 ms 2040 KB Output isn't correct
38 Correct 58 ms 2128 KB Output is correct
39 Incorrect 99 ms 2172 KB Output isn't correct
40 Incorrect 93 ms 2204 KB Output isn't correct
41 Correct 71 ms 2168 KB Output is correct
42 Incorrect 112 ms 2168 KB Output isn't correct
43 Incorrect 118 ms 2396 KB Output isn't correct
44 Correct 83 ms 2296 KB Output is correct
45 Incorrect 142 ms 2296 KB Output isn't correct
46 Incorrect 139 ms 2424 KB Output isn't correct
47 Correct 97 ms 2424 KB Output is correct
48 Incorrect 158 ms 2424 KB Output isn't correct
49 Incorrect 155 ms 2424 KB Output isn't correct
50 Correct 119 ms 2488 KB Output is correct
51 Incorrect 196 ms 2680 KB Output isn't correct
52 Incorrect 178 ms 2556 KB Output isn't correct
53 Correct 129 ms 2552 KB Output is correct
54 Incorrect 213 ms 2808 KB Output isn't correct
55 Incorrect 207 ms 2552 KB Output isn't correct
56 Correct 145 ms 2680 KB Output is correct
57 Incorrect 241 ms 2680 KB Output isn't correct
58 Incorrect 234 ms 2808 KB Output isn't correct
59 Correct 166 ms 2808 KB Output is correct
60 Incorrect 275 ms 2920 KB Output isn't correct
61 Incorrect 265 ms 2808 KB Output isn't correct
62 Correct 188 ms 2936 KB Output is correct
63 Correct 258 ms 2936 KB Output is correct
64 Correct 248 ms 2944 KB Output is correct
65 Correct 260 ms 2936 KB Output is correct
66 Correct 266 ms 2940 KB Output is correct
67 Correct 268 ms 2936 KB Output is correct
68 Correct 243 ms 3140 KB Output is correct
69 Correct 191 ms 3064 KB Output is correct
70 Correct 229 ms 3052 KB Output is correct
71 Correct 237 ms 3120 KB Output is correct
72 Correct 289 ms 3016 KB Output is correct
73 Correct 197 ms 4220 KB Output is correct
74 Correct 275 ms 4348 KB Output is correct
75 Correct 253 ms 4224 KB Output is correct
76 Correct 279 ms 4424 KB Output is correct
77 Correct 248 ms 4440 KB Output is correct
78 Correct 249 ms 3892 KB Output is correct
79 Correct 275 ms 4032 KB Output is correct
80 Correct 244 ms 3904 KB Output is correct
81 Correct 270 ms 3924 KB Output is correct
82 Correct 268 ms 4044 KB Output is correct
83 Correct 281 ms 3876 KB Output is correct
84 Correct 268 ms 3776 KB Output is correct
85 Correct 278 ms 3868 KB Output is correct
86 Correct 285 ms 3812 KB Output is correct
87 Correct 273 ms 3776 KB Output is correct
88 Correct 270 ms 3844 KB Output is correct
89 Correct 257 ms 3684 KB Output is correct
90 Correct 261 ms 3704 KB Output is correct
91 Correct 261 ms 3764 KB Output is correct
92 Correct 244 ms 3704 KB Output is correct