# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792230 |
2023-07-24T19:44:17 Z |
Mathandski |
Mecho (IOI09_mecho) |
C++14 |
|
155 ms |
9068 KB |
#define pb push_back
#define mt make_tuple
#define mp make_pair
#define is insert
#define ll long long
#define vl vector<ll>
#define sl set<ll>
#define msl multiset<ll>
#define pl pair<ll, ll>
#define vpl vector<pair<ll, ll>>
#define f0r(i, begin, end) for (ll i = begin; i < end; i ++)
#define len(x) x.size()
#include "bits/stdc++.h"
using namespace std;
const int INF = 1e9;
int grid[800][800], N, M;
pair<int, int> arrives[800][800];
pl start, home;
bool process1 (int x, int y, int weight) {
if((x < 0) || (x >= N) || (y < 0) || (y >= N)) {
return false;
}
if (grid[x][y] != INF) {
return false;
}
grid[x][y] = weight;
return true;
}
bool process2 (int x, int y, pair<int, int> weight) {
if((x < 0) || (x >= N) || (y < 0) || (y >= N)) {
return false;
}
if (arrives[x][y].first != INF) {
return false;
}
if (grid[x][y] <= weight.first) {
return false;
}
arrives[x][y] = weight;
return true;
}
bool test (int time) {
f0r (i, 0, N) {
f0r (j, 0, N) {
arrives[i][j] = {INF, INF};
}
}
arrives[start.first][start.second] = {time, 0};
queue<pair<int, int>> q;
q.push(start);
while (!q.empty()) {
int x, y; tie(x, y) = q.front();
q.pop();
auto llegar = arrives[x][y];
if((++llegar.second) > M) {
llegar.first ++;
llegar.second = 1;
}
if (process2(x + 1, y, llegar)) {
q.push({x + 1, y});
}
if (process2(x - 1, y, llegar)) {
q.push({x - 1, y});
}
if (process2(x, y + 1, llegar)) {
q.push({x, y + 1});
}
if (process2(x, y - 1, llegar)) {
q.push({x, y - 1});
}
}
return arrives[home.first][home.second].first < INF;
}
ll last_true(ll lo, ll hi) {
lo--;
while (lo < hi) {
ll mid = lo + (hi - lo + 1) / 2;
if (test(mid)) lo = mid;
else hi = mid - 1;
}
return lo;
}
int main () {
cin >> N >> M;
queue<pl> ffill;
f0r (i, 0, N) {
f0r (j, 0, N) {
char a; cin >> a;
if(a == 'T') grid[i][j] = -1;
if(a == 'G') grid[i][j] = INF;
if(a == 'H') {
grid[i][j] = 0;
ffill.push({i, j});
}
if(a == 'M') {
grid[i][j] = INF;
start = {i, j};
}
if(a == 'D') {
grid[i][j] = 1e8;
home = {i, j};
}
}
}
while (!ffill.empty()) {
pl coords = ffill.front();
ll x, y; tie(x, y) = coords;
ffill.pop();
if (process1(x + 1, y, grid[x][y] + 1)) {
ffill.push({x + 1, y});
}
if (process1(x - 1, y, grid[x][y] + 1)) {
ffill.push({x - 1, y});
}
if (process1(x, y + 1, grid[x][y] + 1)) {
ffill.push({x, y + 1});
}
if (process1(x, y - 1, grid[x][y] + 1)) {
ffill.push({x, y - 1});
}
}
cout << last_true(0, grid[start.first][start.second] - 1) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
80 ms |
8644 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
696 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
22 |
Correct |
1 ms |
564 KB |
Output is correct |
23 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Incorrect |
1 ms |
820 KB |
Output isn't correct |
30 |
Correct |
1 ms |
828 KB |
Output is correct |
31 |
Incorrect |
2 ms |
852 KB |
Output isn't correct |
32 |
Correct |
1 ms |
852 KB |
Output is correct |
33 |
Incorrect |
10 ms |
3696 KB |
Output isn't correct |
34 |
Correct |
10 ms |
3712 KB |
Output is correct |
35 |
Correct |
18 ms |
3648 KB |
Output is correct |
36 |
Incorrect |
11 ms |
4160 KB |
Output isn't correct |
37 |
Correct |
11 ms |
4132 KB |
Output is correct |
38 |
Correct |
26 ms |
4200 KB |
Output is correct |
39 |
Incorrect |
13 ms |
4692 KB |
Output isn't correct |
40 |
Correct |
13 ms |
4688 KB |
Output is correct |
41 |
Correct |
33 ms |
4732 KB |
Output is correct |
42 |
Incorrect |
17 ms |
5204 KB |
Output isn't correct |
43 |
Correct |
16 ms |
5188 KB |
Output is correct |
44 |
Correct |
38 ms |
5160 KB |
Output is correct |
45 |
Incorrect |
24 ms |
5756 KB |
Output isn't correct |
46 |
Correct |
20 ms |
5700 KB |
Output is correct |
47 |
Correct |
53 ms |
5796 KB |
Output is correct |
48 |
Incorrect |
23 ms |
6228 KB |
Output isn't correct |
49 |
Correct |
24 ms |
6188 KB |
Output is correct |
50 |
Correct |
53 ms |
6276 KB |
Output is correct |
51 |
Incorrect |
27 ms |
6784 KB |
Output isn't correct |
52 |
Correct |
27 ms |
6780 KB |
Output is correct |
53 |
Correct |
69 ms |
6724 KB |
Output is correct |
54 |
Incorrect |
31 ms |
7332 KB |
Output isn't correct |
55 |
Correct |
31 ms |
7232 KB |
Output is correct |
56 |
Correct |
98 ms |
7452 KB |
Output is correct |
57 |
Incorrect |
36 ms |
7892 KB |
Output isn't correct |
58 |
Correct |
35 ms |
7884 KB |
Output is correct |
59 |
Correct |
87 ms |
7780 KB |
Output is correct |
60 |
Incorrect |
40 ms |
8416 KB |
Output isn't correct |
61 |
Correct |
39 ms |
8412 KB |
Output is correct |
62 |
Correct |
100 ms |
8396 KB |
Output is correct |
63 |
Correct |
102 ms |
8424 KB |
Output is correct |
64 |
Correct |
152 ms |
8332 KB |
Output is correct |
65 |
Correct |
155 ms |
8412 KB |
Output is correct |
66 |
Incorrect |
122 ms |
8424 KB |
Output isn't correct |
67 |
Correct |
114 ms |
8480 KB |
Output is correct |
68 |
Correct |
54 ms |
8396 KB |
Output is correct |
69 |
Correct |
50 ms |
8488 KB |
Output is correct |
70 |
Correct |
48 ms |
8400 KB |
Output is correct |
71 |
Correct |
42 ms |
8400 KB |
Output is correct |
72 |
Correct |
45 ms |
8464 KB |
Output is correct |
73 |
Correct |
54 ms |
8908 KB |
Output is correct |
74 |
Correct |
66 ms |
9068 KB |
Output is correct |
75 |
Correct |
59 ms |
8980 KB |
Output is correct |
76 |
Correct |
63 ms |
8984 KB |
Output is correct |
77 |
Correct |
61 ms |
8928 KB |
Output is correct |
78 |
Correct |
64 ms |
8808 KB |
Output is correct |
79 |
Correct |
56 ms |
8924 KB |
Output is correct |
80 |
Correct |
78 ms |
8860 KB |
Output is correct |
81 |
Correct |
71 ms |
8916 KB |
Output is correct |
82 |
Correct |
59 ms |
8904 KB |
Output is correct |
83 |
Correct |
73 ms |
8848 KB |
Output is correct |
84 |
Correct |
63 ms |
8748 KB |
Output is correct |
85 |
Correct |
63 ms |
8816 KB |
Output is correct |
86 |
Correct |
95 ms |
8776 KB |
Output is correct |
87 |
Correct |
63 ms |
8836 KB |
Output is correct |
88 |
Correct |
73 ms |
8748 KB |
Output is correct |
89 |
Correct |
70 ms |
8748 KB |
Output is correct |
90 |
Correct |
74 ms |
8736 KB |
Output is correct |
91 |
Correct |
95 ms |
8744 KB |
Output is correct |
92 |
Correct |
79 ms |
8640 KB |
Output is correct |