# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
440352 |
2021-07-02T07:00:38 Z |
Karliver |
Mecho (IOI09_mecho) |
C++14 |
|
300 ms |
6952 KB |
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;
const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <typename XPAX>
void ckma(XPAX &x, XPAX y) {
x = (x < y ? y : x);
}
template <typename XPAX>
void ckmi(XPAX &x, XPAX y) {
x = (x > y ? y : x);
}
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
void solve() {
int n;
cin >> n;
int s;
cin >> s;
queue<pairs> q;
V<string> c(n);
forn(i, n) {
cin >> c[i];
//debug(c[i]);
}
auto valid = [&](int i, int j) {
return (i < n && j < n && i > -1 && j > -1 && c[i][j] != 'T');
};
int sx, sy;
int tx, ty;
V<pairs> directions{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
auto dv = [&](int x) {
return x / s;
};
VV<int> bee(n, V<int>(n, INF));
forn(i, n) forn(j, n) {
if(c[i][j] == 'H') {
q.push({i, j});
bee[i][j] = 0;
}
if(c[i][j] == 'D') {
tx = i;
ty = j;
}
if(c[i][j] == 'M') {
sx = i;
sy = j;
}
}
// debug(bee);
while(q.size()) {
int i = q.front().first;
int j = q.front().second;
q.pop();
for(auto dir : directions) {
int ei = i + dir.first;
int ej = j + dir.second;
if(valid(ei, ej) && bee[ei][ej] == INF && c[ei][ej] == 'G') {
bee[ei][ej] = bee[i][j] + 1;
q.push({ei, ej});
}
}
}
auto ck = [&](int mid) -> bool {
VV<int> dis(n, V<int>(n, -1));
dis[sx][sy] = 0;
queue<pairs> q;
q.push({sx, sy});
while(q.size()) {
int i = q.front().first;
int j = q.front().second;
q.pop();
for(auto dir : directions) {
int ei = i + dir.first;
int ej = j + dir.second;
if(valid(ei, ej) && dis[ei][ej] == -1 && bee[ei][ej] > dv(dis[i][j] + 1) + mid) {
dis[ei][ej] = dis[i][j] + 1;
q.push({ei, ej});
}
}
}
//debug(dis);
return (dis[tx][ty] != -1);
};
int low = 0;
int high = bee[sx][sy] - 1;
while(low < high) {
int mid = (low + high + 1) / 2;
if(ck(mid))
low = mid;
else high = mid - 1;
}
cout << (ck(low) ? low : -1) << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
//cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
190 ms |
6880 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
12 ms |
1656 KB |
Output is correct |
34 |
Correct |
11 ms |
1684 KB |
Output is correct |
35 |
Correct |
37 ms |
1556 KB |
Output is correct |
36 |
Correct |
12 ms |
2008 KB |
Output is correct |
37 |
Correct |
13 ms |
1856 KB |
Output is correct |
38 |
Correct |
52 ms |
2076 KB |
Output is correct |
39 |
Correct |
20 ms |
2360 KB |
Output is correct |
40 |
Correct |
17 ms |
2356 KB |
Output is correct |
41 |
Correct |
65 ms |
2444 KB |
Output is correct |
42 |
Correct |
19 ms |
2948 KB |
Output is correct |
43 |
Correct |
19 ms |
2864 KB |
Output is correct |
44 |
Correct |
89 ms |
2884 KB |
Output is correct |
45 |
Correct |
22 ms |
3336 KB |
Output is correct |
46 |
Correct |
29 ms |
3424 KB |
Output is correct |
47 |
Correct |
105 ms |
3420 KB |
Output is correct |
48 |
Correct |
28 ms |
4024 KB |
Output is correct |
49 |
Correct |
32 ms |
3932 KB |
Output is correct |
50 |
Correct |
141 ms |
3940 KB |
Output is correct |
51 |
Correct |
33 ms |
4540 KB |
Output is correct |
52 |
Correct |
35 ms |
4620 KB |
Output is correct |
53 |
Correct |
148 ms |
4596 KB |
Output is correct |
54 |
Correct |
40 ms |
5296 KB |
Output is correct |
55 |
Correct |
46 ms |
5312 KB |
Output is correct |
56 |
Correct |
175 ms |
5280 KB |
Output is correct |
57 |
Correct |
41 ms |
6036 KB |
Output is correct |
58 |
Correct |
41 ms |
6000 KB |
Output is correct |
59 |
Correct |
203 ms |
5992 KB |
Output is correct |
60 |
Correct |
59 ms |
6824 KB |
Output is correct |
61 |
Correct |
53 ms |
6744 KB |
Output is correct |
62 |
Correct |
229 ms |
6752 KB |
Output is correct |
63 |
Correct |
168 ms |
6752 KB |
Output is correct |
64 |
Correct |
300 ms |
6764 KB |
Output is correct |
65 |
Correct |
282 ms |
6836 KB |
Output is correct |
66 |
Correct |
197 ms |
6816 KB |
Output is correct |
67 |
Correct |
192 ms |
6880 KB |
Output is correct |
68 |
Correct |
89 ms |
6916 KB |
Output is correct |
69 |
Correct |
102 ms |
6876 KB |
Output is correct |
70 |
Correct |
115 ms |
6796 KB |
Output is correct |
71 |
Correct |
72 ms |
6784 KB |
Output is correct |
72 |
Incorrect |
75 ms |
6888 KB |
Output isn't correct |
73 |
Incorrect |
145 ms |
6804 KB |
Output isn't correct |
74 |
Correct |
126 ms |
6820 KB |
Output is correct |
75 |
Correct |
139 ms |
6776 KB |
Output is correct |
76 |
Correct |
145 ms |
6828 KB |
Output is correct |
77 |
Correct |
132 ms |
6764 KB |
Output is correct |
78 |
Correct |
135 ms |
6784 KB |
Output is correct |
79 |
Correct |
118 ms |
6952 KB |
Output is correct |
80 |
Correct |
149 ms |
6796 KB |
Output is correct |
81 |
Correct |
130 ms |
6796 KB |
Output is correct |
82 |
Correct |
121 ms |
6788 KB |
Output is correct |
83 |
Correct |
144 ms |
6904 KB |
Output is correct |
84 |
Correct |
142 ms |
6788 KB |
Output is correct |
85 |
Correct |
131 ms |
6772 KB |
Output is correct |
86 |
Correct |
145 ms |
6784 KB |
Output is correct |
87 |
Correct |
195 ms |
6816 KB |
Output is correct |
88 |
Correct |
142 ms |
6784 KB |
Output is correct |
89 |
Correct |
164 ms |
6776 KB |
Output is correct |
90 |
Correct |
169 ms |
6820 KB |
Output is correct |
91 |
Correct |
153 ms |
6872 KB |
Output is correct |
92 |
Correct |
195 ms |
6768 KB |
Output is correct |