# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
953303 |
2024-03-25T19:40:28 Z |
snowman |
Mecho (IOI09_mecho) |
C++17 |
|
249 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 = 0;
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 |
0 ms |
348 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 |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Incorrect |
134 ms |
6372 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
512 KB |
Output isn't 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 |
1 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
1 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 |
1 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
22 |
Incorrect |
1 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 |
344 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
27 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
29 |
Incorrect |
0 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 |
42 ms |
1584 KB |
Output isn't correct |
36 |
Incorrect |
9 ms |
1876 KB |
Output isn't correct |
37 |
Incorrect |
31 ms |
1884 KB |
Output isn't correct |
38 |
Incorrect |
47 ms |
1884 KB |
Output isn't correct |
39 |
Incorrect |
12 ms |
2228 KB |
Output isn't correct |
40 |
Incorrect |
41 ms |
2140 KB |
Output isn't correct |
41 |
Incorrect |
62 ms |
2236 KB |
Output isn't correct |
42 |
Incorrect |
15 ms |
2700 KB |
Output isn't correct |
43 |
Incorrect |
49 ms |
2652 KB |
Output isn't correct |
44 |
Incorrect |
87 ms |
2680 KB |
Output isn't correct |
45 |
Incorrect |
17 ms |
3116 KB |
Output isn't correct |
46 |
Incorrect |
62 ms |
3056 KB |
Output isn't correct |
47 |
Incorrect |
93 ms |
3164 KB |
Output isn't correct |
48 |
Incorrect |
21 ms |
3676 KB |
Output isn't correct |
49 |
Incorrect |
88 ms |
3656 KB |
Output isn't correct |
50 |
Incorrect |
111 ms |
3676 KB |
Output isn't correct |
51 |
Incorrect |
24 ms |
4188 KB |
Output isn't correct |
52 |
Incorrect |
86 ms |
4196 KB |
Output isn't correct |
53 |
Incorrect |
126 ms |
4192 KB |
Output isn't correct |
54 |
Incorrect |
36 ms |
4776 KB |
Output isn't correct |
55 |
Incorrect |
103 ms |
4820 KB |
Output isn't correct |
56 |
Incorrect |
169 ms |
4944 KB |
Output isn't correct |
57 |
Incorrect |
32 ms |
5464 KB |
Output isn't correct |
58 |
Incorrect |
118 ms |
5456 KB |
Output isn't correct |
59 |
Incorrect |
175 ms |
5412 KB |
Output isn't correct |
60 |
Incorrect |
36 ms |
6124 KB |
Output isn't correct |
61 |
Incorrect |
135 ms |
6144 KB |
Output isn't correct |
62 |
Incorrect |
237 ms |
6156 KB |
Output isn't correct |
63 |
Incorrect |
119 ms |
6152 KB |
Output isn't correct |
64 |
Incorrect |
249 ms |
6156 KB |
Output isn't correct |
65 |
Incorrect |
170 ms |
6300 KB |
Output isn't correct |
66 |
Incorrect |
146 ms |
6192 KB |
Output isn't correct |
67 |
Incorrect |
135 ms |
6204 KB |
Output isn't correct |
68 |
Incorrect |
87 ms |
6192 KB |
Output isn't correct |
69 |
Incorrect |
85 ms |
6184 KB |
Output isn't correct |
70 |
Incorrect |
64 ms |
6216 KB |
Output isn't correct |
71 |
Incorrect |
65 ms |
6228 KB |
Output isn't correct |
72 |
Incorrect |
49 ms |
6204 KB |
Output isn't correct |
73 |
Incorrect |
70 ms |
6264 KB |
Output isn't correct |
74 |
Incorrect |
111 ms |
6460 KB |
Output isn't correct |
75 |
Incorrect |
104 ms |
6232 KB |
Output isn't correct |
76 |
Incorrect |
96 ms |
6232 KB |
Output isn't correct |
77 |
Incorrect |
113 ms |
6184 KB |
Output isn't correct |
78 |
Incorrect |
113 ms |
6368 KB |
Output isn't correct |
79 |
Incorrect |
102 ms |
6252 KB |
Output isn't correct |
80 |
Incorrect |
90 ms |
6240 KB |
Output isn't correct |
81 |
Incorrect |
101 ms |
6200 KB |
Output isn't correct |
82 |
Incorrect |
94 ms |
6184 KB |
Output isn't correct |
83 |
Incorrect |
109 ms |
6228 KB |
Output isn't correct |
84 |
Incorrect |
115 ms |
6196 KB |
Output isn't correct |
85 |
Incorrect |
101 ms |
6236 KB |
Output isn't correct |
86 |
Incorrect |
110 ms |
6264 KB |
Output isn't correct |
87 |
Incorrect |
116 ms |
6220 KB |
Output isn't correct |
88 |
Incorrect |
128 ms |
6184 KB |
Output isn't correct |
89 |
Incorrect |
139 ms |
6136 KB |
Output isn't correct |
90 |
Incorrect |
129 ms |
6200 KB |
Output isn't correct |
91 |
Incorrect |
135 ms |
6176 KB |
Output isn't correct |
92 |
Incorrect |
141 ms |
6240 KB |
Output isn't correct |