# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
953300 |
2024-03-25T19:36:07 Z |
snowman |
Mecho (IOI09_mecho) |
C++17 |
|
281 ms |
6500 KB |
#include <bits/stdc++.h>
using namespace std;
//Soltan Cristian
#define ll long long
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pb push_back
#define st first
#define nd second
#define sz(x) (ll)x.size()
#define rall(x) x.rbegin(), x.rend()
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int mxa = 2 * 1e5 + 2;
// string __fname = "maxflow";
// ifstream in(__fname + ".in");
// ofstream out (__fname + ".out");
// #define cin in
// #define cout out
int n, s;
vector<vector<char>> mapa;
bool validB(int x, int y){
if(x >= 0 && x < n && y >= 0 && y < n && mapa[x][y] != 'T' && mapa[x][y] != 'D'){
return true;
}
return false;
}
bool valid(int x, int y){
if(x >= 0 && x < n && y >= 0 && y < n && mapa[x][y] != 'T'){
return true;
}
return false;
}
void solve(){
cin >> n >> s;
mapa = vector<vector<char>>(n, vector<char>(n));
vector<pair<int,int>> stup;
pair<int, int> start, finish;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
char x;
cin >> x;
if(x == 'H') stup.pb({i, j});
if(x == 'M') start = {i, j};
if(x == 'D') finish = {i, j};
mapa[i][j] = x;
}
}
vector<vector<int>> bees(n, vector<int>(n, INT_MAX));
queue<pair<int, int>> qB;
for(int i = 0; i < sz(stup); i++){
bees[stup[i].st][stup[i].nd] = 0;
qB.push({stup[i].st, stup[i].nd});
}
// cout << "a\n";
while(!qB.empty()){
pair<int, int> u = qB.front();
qB.pop();
for(int i = 0; i < 4; i++){
if(!validB(u.st + dx[i], u.nd + dy[i])) continue;
if(bees[u.st][u.nd] + s < bees[u.st + dx[i]][u.nd + dy[i]]){
qB.push({u.st + dx[i], u.nd + dy[i]});
bees[u.st + dx[i]][u.nd + dy[i]] = bees[u.st][u.nd] + s;
}
}
}
if(bees[start.st][start.nd] == INT_MAX){
cout << -1 << '\n';
return;
}
int l = 0, r = 2 * n * n;
int ans = -1;
while(l <= r){
int mid = (l + r) / 2;
vector<vector<int>> h(n, vector<int>(n, INT_MAX));
h[start.st][start.nd] = mid;
queue<pair<int,int>> q;
q.push({start.st, start.nd});
while(!q.empty()){
pair<int, int> u = q.front();
q.pop();
for(int i = 0; i < 4; i++){
if(!valid(u.st + dx[i], u.nd + dy[i])) continue;
if(h[u.st][u.nd] + 1 < bees[u.st + dx[i]][u.nd + dy[i]] &&
h[u.st][u.nd] + 1 < h[u.st + dx[i]][u.nd + dy[i]]){
q.push({u.st + dx[i], u.nd + dy[i]});
h[u.st + dx[i]][u.nd + dy[i]] = h[u.st][u.nd] + 1;
}
}
}
if(h[finish.st][finish.nd] < INT_MAX){
cout << mid << ' ' << ans << '\n';
ans = max(ans, mid);
l = mid + 1;
}
else r = mid - 1;
}
// cout << ans << '\n';
// if(ans == -1){
// cout << -1<< '\n';
// }
// else
cout << ans / s << '\n';
}
int main()
{
// ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << (setprecision(10));
// int t;
// cin >> t;
// while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
129 ms |
6204 KB |
Output isn't correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
33 |
Incorrect |
7 ms |
1520 KB |
Output isn't correct |
34 |
Incorrect |
23 ms |
1372 KB |
Output isn't correct |
35 |
Incorrect |
34 ms |
1560 KB |
Output isn't correct |
36 |
Incorrect |
9 ms |
1756 KB |
Output isn't correct |
37 |
Incorrect |
32 ms |
1884 KB |
Output isn't correct |
38 |
Incorrect |
52 ms |
1896 KB |
Output isn't correct |
39 |
Incorrect |
12 ms |
2228 KB |
Output isn't correct |
40 |
Incorrect |
39 ms |
2140 KB |
Output isn't correct |
41 |
Incorrect |
59 ms |
2248 KB |
Output isn't correct |
42 |
Incorrect |
15 ms |
2696 KB |
Output isn't correct |
43 |
Incorrect |
48 ms |
2456 KB |
Output isn't correct |
44 |
Incorrect |
74 ms |
2700 KB |
Output isn't correct |
45 |
Incorrect |
18 ms |
3132 KB |
Output isn't correct |
46 |
Incorrect |
62 ms |
2908 KB |
Output isn't correct |
47 |
Incorrect |
90 ms |
3132 KB |
Output isn't correct |
48 |
Incorrect |
21 ms |
3672 KB |
Output isn't correct |
49 |
Incorrect |
78 ms |
3416 KB |
Output isn't correct |
50 |
Incorrect |
116 ms |
3728 KB |
Output isn't correct |
51 |
Incorrect |
24 ms |
4188 KB |
Output isn't correct |
52 |
Incorrect |
87 ms |
4224 KB |
Output isn't correct |
53 |
Incorrect |
126 ms |
4224 KB |
Output isn't correct |
54 |
Incorrect |
27 ms |
4692 KB |
Output isn't correct |
55 |
Incorrect |
98 ms |
4816 KB |
Output isn't correct |
56 |
Incorrect |
166 ms |
5060 KB |
Output isn't correct |
57 |
Incorrect |
36 ms |
5352 KB |
Output isn't correct |
58 |
Incorrect |
118 ms |
5464 KB |
Output isn't correct |
59 |
Incorrect |
176 ms |
5464 KB |
Output isn't correct |
60 |
Incorrect |
38 ms |
6156 KB |
Output isn't correct |
61 |
Incorrect |
134 ms |
5972 KB |
Output isn't correct |
62 |
Incorrect |
219 ms |
6188 KB |
Output isn't correct |
63 |
Incorrect |
119 ms |
6152 KB |
Output isn't correct |
64 |
Incorrect |
281 ms |
6156 KB |
Output isn't correct |
65 |
Incorrect |
162 ms |
6140 KB |
Output isn't correct |
66 |
Incorrect |
147 ms |
6160 KB |
Output isn't correct |
67 |
Incorrect |
137 ms |
6324 KB |
Output isn't correct |
68 |
Incorrect |
87 ms |
6196 KB |
Output isn't correct |
69 |
Incorrect |
79 ms |
6172 KB |
Output isn't correct |
70 |
Incorrect |
65 ms |
6188 KB |
Output isn't correct |
71 |
Incorrect |
64 ms |
6232 KB |
Output isn't correct |
72 |
Incorrect |
50 ms |
6128 KB |
Output isn't correct |
73 |
Incorrect |
68 ms |
6240 KB |
Output isn't correct |
74 |
Incorrect |
113 ms |
6224 KB |
Output isn't correct |
75 |
Incorrect |
98 ms |
6216 KB |
Output isn't correct |
76 |
Incorrect |
102 ms |
6396 KB |
Output isn't correct |
77 |
Incorrect |
105 ms |
6228 KB |
Output isn't correct |
78 |
Incorrect |
108 ms |
6220 KB |
Output isn't correct |
79 |
Incorrect |
100 ms |
6220 KB |
Output isn't correct |
80 |
Incorrect |
92 ms |
6500 KB |
Output isn't correct |
81 |
Incorrect |
102 ms |
6236 KB |
Output isn't correct |
82 |
Incorrect |
89 ms |
6196 KB |
Output isn't correct |
83 |
Incorrect |
112 ms |
6244 KB |
Output isn't correct |
84 |
Incorrect |
126 ms |
6416 KB |
Output isn't correct |
85 |
Incorrect |
100 ms |
6232 KB |
Output isn't correct |
86 |
Incorrect |
106 ms |
6236 KB |
Output isn't correct |
87 |
Incorrect |
116 ms |
6216 KB |
Output isn't correct |
88 |
Incorrect |
115 ms |
6192 KB |
Output isn't correct |
89 |
Incorrect |
150 ms |
6128 KB |
Output isn't correct |
90 |
Incorrect |
135 ms |
6188 KB |
Output isn't correct |
91 |
Incorrect |
138 ms |
6448 KB |
Output isn't correct |
92 |
Incorrect |
119 ms |
6188 KB |
Output isn't correct |