# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884660 |
2023-12-08T00:41:03 Z |
xjonwang |
Mecho (IOI09_mecho) |
C++17 |
|
185 ms |
6304 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=-1, 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 |
344 KB |
Output isn't correct |
3 |
Correct |
0 ms |
600 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 |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
93 ms |
6244 KB |
Output isn't correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
6 ms |
1560 KB |
Output is correct |
34 |
Correct |
6 ms |
1572 KB |
Output is correct |
35 |
Correct |
21 ms |
1572 KB |
Output is correct |
36 |
Correct |
8 ms |
1784 KB |
Output is correct |
37 |
Correct |
7 ms |
1884 KB |
Output is correct |
38 |
Correct |
27 ms |
1880 KB |
Output is correct |
39 |
Correct |
14 ms |
2280 KB |
Output is correct |
40 |
Correct |
10 ms |
2276 KB |
Output is correct |
41 |
Correct |
38 ms |
2256 KB |
Output is correct |
42 |
Correct |
14 ms |
2716 KB |
Output is correct |
43 |
Correct |
14 ms |
2716 KB |
Output is correct |
44 |
Correct |
56 ms |
2772 KB |
Output is correct |
45 |
Correct |
17 ms |
3240 KB |
Output is correct |
46 |
Correct |
15 ms |
3284 KB |
Output is correct |
47 |
Correct |
56 ms |
3224 KB |
Output is correct |
48 |
Correct |
19 ms |
3796 KB |
Output is correct |
49 |
Correct |
21 ms |
3684 KB |
Output is correct |
50 |
Correct |
73 ms |
3936 KB |
Output is correct |
51 |
Correct |
22 ms |
4304 KB |
Output is correct |
52 |
Correct |
26 ms |
4308 KB |
Output is correct |
53 |
Correct |
85 ms |
4296 KB |
Output is correct |
54 |
Correct |
30 ms |
4976 KB |
Output is correct |
55 |
Correct |
26 ms |
4936 KB |
Output is correct |
56 |
Correct |
103 ms |
5000 KB |
Output is correct |
57 |
Correct |
28 ms |
5536 KB |
Output is correct |
58 |
Correct |
31 ms |
5528 KB |
Output is correct |
59 |
Correct |
113 ms |
5508 KB |
Output is correct |
60 |
Correct |
33 ms |
6232 KB |
Output is correct |
61 |
Correct |
29 ms |
6232 KB |
Output is correct |
62 |
Correct |
129 ms |
6236 KB |
Output is correct |
63 |
Correct |
99 ms |
6196 KB |
Output is correct |
64 |
Correct |
176 ms |
6204 KB |
Output is correct |
65 |
Correct |
158 ms |
6184 KB |
Output is correct |
66 |
Correct |
185 ms |
6304 KB |
Output is correct |
67 |
Correct |
100 ms |
6204 KB |
Output is correct |
68 |
Correct |
52 ms |
6236 KB |
Output is correct |
69 |
Correct |
56 ms |
6264 KB |
Output is correct |
70 |
Correct |
43 ms |
6288 KB |
Output is correct |
71 |
Correct |
45 ms |
6240 KB |
Output is correct |
72 |
Incorrect |
41 ms |
6268 KB |
Output isn't correct |
73 |
Incorrect |
41 ms |
6268 KB |
Output isn't correct |
74 |
Correct |
69 ms |
6248 KB |
Output is correct |
75 |
Correct |
75 ms |
6264 KB |
Output is correct |
76 |
Correct |
75 ms |
6264 KB |
Output is correct |
77 |
Correct |
88 ms |
6236 KB |
Output is correct |
78 |
Correct |
73 ms |
6224 KB |
Output is correct |
79 |
Correct |
64 ms |
6256 KB |
Output is correct |
80 |
Correct |
76 ms |
6300 KB |
Output is correct |
81 |
Correct |
71 ms |
6260 KB |
Output is correct |
82 |
Correct |
69 ms |
6264 KB |
Output is correct |
83 |
Correct |
75 ms |
6244 KB |
Output is correct |
84 |
Correct |
87 ms |
6236 KB |
Output is correct |
85 |
Correct |
93 ms |
6256 KB |
Output is correct |
86 |
Correct |
90 ms |
6244 KB |
Output is correct |
87 |
Correct |
86 ms |
6240 KB |
Output is correct |
88 |
Correct |
76 ms |
6256 KB |
Output is correct |
89 |
Correct |
89 ms |
6276 KB |
Output is correct |
90 |
Correct |
102 ms |
6220 KB |
Output is correct |
91 |
Correct |
90 ms |
6228 KB |
Output is correct |
92 |
Correct |
105 ms |
6120 KB |
Output is correct |