# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
953298 |
2024-03-25T19:34:29 Z |
snowman |
Mecho (IOI09_mecho) |
C++17 |
|
254 ms |
6460 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 |
0 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
130 ms |
6204 KB |
Output isn't correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 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 |
1 ms |
348 KB |
Output isn't correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
432 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 |
348 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
33 |
Incorrect |
7 ms |
1516 KB |
Output isn't correct |
34 |
Incorrect |
23 ms |
1372 KB |
Output isn't correct |
35 |
Incorrect |
37 ms |
1552 KB |
Output isn't correct |
36 |
Incorrect |
9 ms |
2080 KB |
Output isn't correct |
37 |
Incorrect |
31 ms |
1884 KB |
Output isn't correct |
38 |
Incorrect |
51 ms |
1884 KB |
Output isn't correct |
39 |
Incorrect |
12 ms |
2224 KB |
Output isn't correct |
40 |
Incorrect |
40 ms |
2140 KB |
Output isn't correct |
41 |
Incorrect |
60 ms |
2232 KB |
Output isn't correct |
42 |
Incorrect |
14 ms |
2696 KB |
Output isn't correct |
43 |
Incorrect |
48 ms |
2648 KB |
Output isn't correct |
44 |
Incorrect |
73 ms |
2680 KB |
Output isn't correct |
45 |
Incorrect |
18 ms |
3116 KB |
Output isn't correct |
46 |
Incorrect |
60 ms |
2904 KB |
Output isn't correct |
47 |
Incorrect |
90 ms |
3132 KB |
Output isn't correct |
48 |
Incorrect |
23 ms |
3652 KB |
Output isn't correct |
49 |
Incorrect |
72 ms |
3420 KB |
Output isn't correct |
50 |
Incorrect |
126 ms |
3648 KB |
Output isn't correct |
51 |
Incorrect |
24 ms |
4184 KB |
Output isn't correct |
52 |
Incorrect |
86 ms |
4184 KB |
Output isn't correct |
53 |
Incorrect |
131 ms |
4324 KB |
Output isn't correct |
54 |
Incorrect |
28 ms |
4672 KB |
Output isn't correct |
55 |
Incorrect |
100 ms |
4816 KB |
Output isn't correct |
56 |
Incorrect |
153 ms |
4820 KB |
Output isn't correct |
57 |
Incorrect |
32 ms |
5412 KB |
Output isn't correct |
58 |
Incorrect |
147 ms |
5604 KB |
Output isn't correct |
59 |
Incorrect |
175 ms |
5464 KB |
Output isn't correct |
60 |
Incorrect |
36 ms |
6128 KB |
Output isn't correct |
61 |
Incorrect |
135 ms |
5980 KB |
Output isn't correct |
62 |
Incorrect |
206 ms |
6316 KB |
Output isn't correct |
63 |
Incorrect |
118 ms |
6152 KB |
Output isn't correct |
64 |
Incorrect |
254 ms |
5952 KB |
Output isn't correct |
65 |
Incorrect |
160 ms |
6352 KB |
Output isn't correct |
66 |
Incorrect |
141 ms |
6164 KB |
Output isn't correct |
67 |
Correct |
127 ms |
6156 KB |
Output is correct |
68 |
Incorrect |
86 ms |
6196 KB |
Output isn't correct |
69 |
Incorrect |
76 ms |
6176 KB |
Output isn't correct |
70 |
Incorrect |
62 ms |
6220 KB |
Output isn't correct |
71 |
Incorrect |
63 ms |
6256 KB |
Output isn't correct |
72 |
Incorrect |
47 ms |
6192 KB |
Output isn't correct |
73 |
Incorrect |
68 ms |
6240 KB |
Output isn't correct |
74 |
Incorrect |
105 ms |
6328 KB |
Output isn't correct |
75 |
Incorrect |
99 ms |
6216 KB |
Output isn't correct |
76 |
Incorrect |
92 ms |
6276 KB |
Output isn't correct |
77 |
Incorrect |
107 ms |
6200 KB |
Output isn't correct |
78 |
Correct |
109 ms |
6216 KB |
Output is correct |
79 |
Incorrect |
104 ms |
6224 KB |
Output isn't correct |
80 |
Incorrect |
90 ms |
6244 KB |
Output isn't correct |
81 |
Incorrect |
100 ms |
6212 KB |
Output isn't correct |
82 |
Incorrect |
89 ms |
6196 KB |
Output isn't correct |
83 |
Incorrect |
114 ms |
6236 KB |
Output isn't correct |
84 |
Incorrect |
116 ms |
6124 KB |
Output isn't correct |
85 |
Incorrect |
111 ms |
6212 KB |
Output isn't correct |
86 |
Incorrect |
105 ms |
6216 KB |
Output isn't correct |
87 |
Incorrect |
115 ms |
6216 KB |
Output isn't correct |
88 |
Incorrect |
116 ms |
6256 KB |
Output isn't correct |
89 |
Incorrect |
140 ms |
6012 KB |
Output isn't correct |
90 |
Incorrect |
122 ms |
6460 KB |
Output isn't correct |
91 |
Incorrect |
137 ms |
6192 KB |
Output isn't correct |
92 |
Incorrect |
117 ms |
6192 KB |
Output isn't correct |