# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
571023 |
2022-06-01T05:08:43 Z |
f4t4nt |
Mecho (IOI09_mecho) |
C++ |
|
1000 ms |
16400 KB |
#include <algorithm>
#include <cmath>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ch = char;
using str = string;
#define pb push_back
#define elif else if
#define sz(C) (ll) C.size()
#define mp make_pair
#define mt make_tuple
#define flip(C) reverse(C.begin(), C.end())
#define ssort(C) sort(C.begin(), C.end())
#define rsort(C) sort(C.begin(), C.end(), greater<>())
#define FOR(x, e) for(ll x = 0; x < (ll) e; x++)
#define FORR(x, e) for(ll x = (ll) e - 1; x >= 0; x--)
#define FOB(x, b, e) for(auto x = b; x < e; x++)
#define FOI(x, e, i) for(ll x = 0; x < (ll) e; x += (ll) i)
#define FOBI(x, b, e, i) for(ll x = (ll) b; x < (ll) e; x += (ll) i)
#define FORE(x, C) for(auto &x : C)
#ifdef LOCAL
#include "tester.cpp"
#define main test_main
extern istringstream fin;
extern ostringstream fout;
string test_file_name = "tests";
#define cin fin
#define cout fout
#endif
vector<int> di { -1, 0, 1, 0};
vector<int> dj { 0, -1, 0, 1};
void fill_b(ll &n, vector<vector<char>> &g, queue<pair<ll, ll>> &bfs_b, vector<vector<ll>> &d_b) {
while(sz(bfs_b)) {
ll i0 = bfs_b.front().first, j0 = bfs_b.front().second;
bfs_b.pop();
FOR(k, 4) {
ll i1 = i0 + di[k], j1 = j0 + dj[k];
if(i1 < 0 || i1 >= n || j1 < 0 || j1 >= n) continue;
if(g[i1][j1] == 'T' || g[i1][j1] == 'D') continue;
if(d_b[i1][j1] != 1e18) continue;
d_b[i1][j1] = d_b[i0][j0] + 1;
bfs_b.push({i1, j1});
}
}
}
bool valid(ll &mid, ll &n, ll &s, vector<vector<ll>> &d_b, vector<vector<char>> &g, queue<pair<ll, ll>> bfs_m, vector<vector<ll>> d_m) {
while(sz(bfs_m)) {
ll i0 = bfs_m.front().first, j0 = bfs_m.front().second, d = d_m[i0][j0] + 1;
bfs_m.pop();
FOR(k, 4) {
ll i1 = i0 + di[k], j1 = j0 + dj[k];
if(i1 < 0 || i1 >= n || j1 < 0 || j1 >= n) continue;
if(g[i1][j1] == 'T') continue;
if(d_m[i1][j1] != 1e18) continue;
if(d_b[i1][j1] * s <= mid * s + d) continue;
if(g[i1][j1] == 'D') return true;
d_m[i1][j1] = d;
bfs_m.push({i1, j1});
}
}
return false;
}
int main() {
ll n, s, lo = 0, hi = 1e18;
cin >> n >> s;
vector<vector<char>> g(n, vector<char>(n));
vector<vector<ll>> d_b(n, vector<ll>(n, 1e18)), d_m(n, vector<ll>(n, 1e18));
queue<pair<ll, ll>> bfs_b, bfs_m;
FOR(i, n) FOR(j, n) {
cin >> g[i][j];
if(g[i][j] == 'H') {
bfs_b.push({i, j});
d_b[i][j] = 0;
}
elif(g[i][j] == 'M') {
bfs_m.push({i, j});
d_m[i][j] = 0;
}
}
fill_b(n, g, bfs_b, d_b);
while(hi - lo > 0) {
ll mid = lo + (hi - lo + 1) / 2;
if(valid(mid, n, s, d_b, g, bfs_m, d_m)) lo = mid;
else hi = mid - 1;
}
if(valid(lo, n, s, d_b, g, bfs_m, d_m)) cout << lo << '\n';
else cout << "-1\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
976 ms |
16148 KB |
Output isn't correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
33 |
Correct |
35 ms |
3340 KB |
Output is correct |
34 |
Incorrect |
62 ms |
3516 KB |
Output isn't correct |
35 |
Incorrect |
145 ms |
3340 KB |
Output isn't correct |
36 |
Correct |
39 ms |
4260 KB |
Output is correct |
37 |
Incorrect |
120 ms |
4384 KB |
Output isn't correct |
38 |
Incorrect |
194 ms |
4260 KB |
Output isn't correct |
39 |
Correct |
50 ms |
5264 KB |
Output is correct |
40 |
Incorrect |
59 ms |
5496 KB |
Output isn't correct |
41 |
Incorrect |
193 ms |
5356 KB |
Output isn't correct |
42 |
Correct |
67 ms |
6624 KB |
Output is correct |
43 |
Incorrect |
146 ms |
6632 KB |
Output isn't correct |
44 |
Incorrect |
226 ms |
6588 KB |
Output isn't correct |
45 |
Correct |
83 ms |
7884 KB |
Output is correct |
46 |
Incorrect |
206 ms |
7800 KB |
Output isn't correct |
47 |
Incorrect |
460 ms |
7860 KB |
Output isn't correct |
48 |
Correct |
98 ms |
9264 KB |
Output is correct |
49 |
Incorrect |
100 ms |
9396 KB |
Output isn't correct |
50 |
Incorrect |
519 ms |
9204 KB |
Output isn't correct |
51 |
Correct |
113 ms |
10876 KB |
Output is correct |
52 |
Incorrect |
298 ms |
10980 KB |
Output isn't correct |
53 |
Incorrect |
338 ms |
10728 KB |
Output isn't correct |
54 |
Correct |
147 ms |
12556 KB |
Output is correct |
55 |
Incorrect |
136 ms |
12552 KB |
Output isn't correct |
56 |
Incorrect |
736 ms |
12392 KB |
Output isn't correct |
57 |
Correct |
183 ms |
14264 KB |
Output is correct |
58 |
Incorrect |
157 ms |
14352 KB |
Output isn't correct |
59 |
Incorrect |
797 ms |
14268 KB |
Output isn't correct |
60 |
Correct |
196 ms |
16400 KB |
Output is correct |
61 |
Incorrect |
441 ms |
16164 KB |
Output isn't correct |
62 |
Incorrect |
576 ms |
16076 KB |
Output isn't correct |
63 |
Correct |
314 ms |
16216 KB |
Output is correct |
64 |
Incorrect |
581 ms |
16288 KB |
Output isn't correct |
65 |
Correct |
414 ms |
16172 KB |
Output is correct |
66 |
Correct |
369 ms |
16204 KB |
Output is correct |
67 |
Correct |
325 ms |
16196 KB |
Output is correct |
68 |
Incorrect |
865 ms |
16244 KB |
Output isn't correct |
69 |
Execution timed out |
1093 ms |
16200 KB |
Time limit exceeded |
70 |
Incorrect |
952 ms |
16096 KB |
Output isn't correct |
71 |
Incorrect |
224 ms |
16172 KB |
Output isn't correct |
72 |
Incorrect |
915 ms |
16144 KB |
Output isn't correct |
73 |
Incorrect |
229 ms |
16212 KB |
Output isn't correct |
74 |
Incorrect |
711 ms |
16244 KB |
Output isn't correct |
75 |
Incorrect |
290 ms |
16272 KB |
Output isn't correct |
76 |
Correct |
248 ms |
16276 KB |
Output is correct |
77 |
Incorrect |
845 ms |
16220 KB |
Output isn't correct |
78 |
Correct |
284 ms |
16292 KB |
Output is correct |
79 |
Execution timed out |
1084 ms |
16184 KB |
Time limit exceeded |
80 |
Incorrect |
270 ms |
16252 KB |
Output isn't correct |
81 |
Correct |
323 ms |
16200 KB |
Output is correct |
82 |
Incorrect |
780 ms |
16132 KB |
Output isn't correct |
83 |
Incorrect |
286 ms |
16232 KB |
Output isn't correct |
84 |
Incorrect |
864 ms |
16232 KB |
Output isn't correct |
85 |
Incorrect |
851 ms |
16228 KB |
Output isn't correct |
86 |
Incorrect |
295 ms |
16216 KB |
Output isn't correct |
87 |
Incorrect |
849 ms |
16352 KB |
Output isn't correct |
88 |
Incorrect |
902 ms |
16180 KB |
Output isn't correct |
89 |
Incorrect |
410 ms |
16088 KB |
Output isn't correct |
90 |
Incorrect |
886 ms |
16100 KB |
Output isn't correct |
91 |
Incorrect |
332 ms |
16216 KB |
Output isn't correct |
92 |
Incorrect |
307 ms |
16256 KB |
Output isn't correct |