Submission #884659

# Submission time Handle Problem Language Result Execution time Memory
884659 2023-12-08T00:38:48 Z xjonwang Mecho (IOI09_mecho) C++17
57 / 100
181 ms 7420 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ar array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define s second

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
} 

ll FIRSTTRUE(function<bool(ll)> f, ll lb, ll rb) {
	while(lb<rb) {
		ll mb=(lb+rb)/2;
		f(mb)?rb=mb:lb=mb+1; 
	} 
	return lb;
}
ll LASTTRUE(function<bool(ll)> f, ll lb, ll rb) {
	while(lb<rb) {
		ll mb=(lb+rb+1)/2;
		f(mb)?lb=mb:rb=mb-1; 
	} 
	return lb;
}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class A, class B> void read(pair<A, B>& x);
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	EACH(a, x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	EACH(a, x)
		read(a);
}
template<class A, class B> void read(pair<A, B>& x) {
	cin >> x.first >> x.second;
}


string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vt<bool> v) {
	string res;
	FOR(sz(v))
		res+=char('0'+v[i]);
	return res;
}

template<size_t S> string to_string(bitset<S> b) {
	string res;
	FOR(S)
		res+=char('0'+b[i]);
	return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
		if(!f)
			res+=' ';
		f=0;
		res+=to_string(x);
	}
    return res;
}
template<class A, class B> string to_string(pair<A, B>& x) {
	return to_string(x.first) + ' ' + to_string(x.second);
}

template<class A> void write(A x) {
	cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) { 
	write(h);
	write(t...);
}
void print() {
	write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) { 
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}

int dr[4]={1, -1, 0, 0}, dc[4]={0, 0, 1, -1};

int n, k, m1, m2, d1, d2;
vt<vt<int>> bd;
vt<vt<char>> g;

bool check(int x) {
	vt<vt<int>> dist(n, vt<int>(n, -1));
	queue<pii> q;
	dist[m1][m2]=0, q.push({m1, m2});
	while (sz(q)) {
		pii v=q.front(); q.pop();
		FOR(4) {
			int r=v.f+dr[i], c=v.s+dc[i];
			if (r>=0 && r<n && c>=0 && c<n && g[r][c]!='T' && dist[r][c]==-1 && (dist[v.f][v.s]+1)/k+x<bd[r][c]) {
				if (r==d1 && c==d2) return true;
				dist[r][c]=dist[v.f][v.s]+1;
				q.push({r, c});
			}
		}
	}
	return false;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	read(n, k);
	g.assign(n, vt<char>(n)), bd.assign(n, vt<int>(n, -1));
	vt<pii> h;
	char x;
	FOR(n) {
		FOR(j, n) {
			read(x);
			g[i][j]=x;
			if (x=='M') m1=i, m2=j;
			else if (x=='D') d1=i, d2=j;
			else if (x=='H') h.pb({i, j});
		}
	}
	queue<pii> q;
	EACH(p, h) bd[p.f][p.s]=0, q.push({p.f, p.s});
	while (sz(q)) {
		pii v=q.front(); q.pop();
		FOR(4) {
			int r=v.f+dr[i], c=v.s+dc[i];
			if (r>=0 && r<n && c>=0 && c<n && g[r][c]!='T' && bd[r][c]==-1) {
				bd[r][c]=bd[v.f][v.s]+1;
				q.push({r, c});
			}
		}
	}
	int l=0, r=1e6;
	for (int i=r-l; i>0; i/=2) while (l+i<=r && check(l+i)) l+=i;
	print(l);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Incorrect 109 ms 7204 KB Output isn't correct
8 Incorrect 0 ms 344 KB Output isn't correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Incorrect 1 ms 456 KB Output isn't correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 408 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 7 ms 1680 KB Output is correct
34 Correct 7 ms 1692 KB Output is correct
35 Correct 22 ms 1692 KB Output is correct
36 Correct 8 ms 2140 KB Output is correct
37 Correct 9 ms 1944 KB Output is correct
38 Correct 27 ms 2140 KB Output is correct
39 Correct 11 ms 2476 KB Output is correct
40 Correct 10 ms 2436 KB Output is correct
41 Correct 34 ms 2484 KB Output is correct
42 Correct 14 ms 3064 KB Output is correct
43 Correct 13 ms 2952 KB Output is correct
44 Correct 43 ms 2964 KB Output is correct
45 Correct 15 ms 3468 KB Output is correct
46 Correct 15 ms 3452 KB Output is correct
47 Correct 58 ms 3504 KB Output is correct
48 Correct 19 ms 4124 KB Output is correct
49 Correct 18 ms 4136 KB Output is correct
50 Correct 62 ms 4120 KB Output is correct
51 Correct 21 ms 4672 KB Output is correct
52 Correct 21 ms 4756 KB Output is correct
53 Correct 74 ms 4676 KB Output is correct
54 Correct 26 ms 5404 KB Output is correct
55 Correct 28 ms 5396 KB Output is correct
56 Correct 86 ms 5348 KB Output is correct
57 Correct 39 ms 6116 KB Output is correct
58 Correct 29 ms 6100 KB Output is correct
59 Correct 98 ms 6076 KB Output is correct
60 Correct 36 ms 6860 KB Output is correct
61 Correct 30 ms 6840 KB Output is correct
62 Correct 124 ms 6976 KB Output is correct
63 Correct 85 ms 6844 KB Output is correct
64 Correct 161 ms 6860 KB Output is correct
65 Correct 181 ms 6808 KB Output is correct
66 Correct 174 ms 6820 KB Output is correct
67 Incorrect 98 ms 6816 KB Output isn't correct
68 Correct 55 ms 6856 KB Output is correct
69 Correct 53 ms 6872 KB Output is correct
70 Correct 47 ms 6876 KB Output is correct
71 Correct 40 ms 6880 KB Output is correct
72 Incorrect 43 ms 6908 KB Output isn't correct
73 Incorrect 44 ms 6928 KB Output isn't correct
74 Correct 76 ms 6876 KB Output is correct
75 Correct 87 ms 6936 KB Output is correct
76 Correct 64 ms 6908 KB Output is correct
77 Correct 70 ms 6880 KB Output is correct
78 Incorrect 71 ms 6968 KB Output isn't correct
79 Correct 62 ms 6932 KB Output is correct
80 Correct 82 ms 7420 KB Output is correct
81 Correct 76 ms 6868 KB Output is correct
82 Correct 68 ms 6908 KB Output is correct
83 Correct 70 ms 6880 KB Output is correct
84 Correct 73 ms 6872 KB Output is correct
85 Correct 79 ms 6932 KB Output is correct
86 Correct 85 ms 6900 KB Output is correct
87 Correct 75 ms 6872 KB Output is correct
88 Correct 74 ms 6868 KB Output is correct
89 Correct 95 ms 6892 KB Output is correct
90 Correct 94 ms 6848 KB Output is correct
91 Correct 98 ms 6940 KB Output is correct
92 Correct 90 ms 6760 KB Output is correct