#include <bits/stdc++.h>
/*--------------------------------------------------------------------*/
#define INF 3*100*1000 + 5
#define MAX 1000000
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define intt int64_t
#define piic pair<int64_t, int64_t>
typedef long long ll;
using namespace std;
/*--------------------------------------------------------------------*/
int n, s;
pii b, home;
queue<pii> hives;
vector<string> grid;
int filltime[500][500]{INT_MAX}, beetime[500][500], visited[500][500];
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
int inside(int x, int y){
return (x> -1 && x < n && y > -1 && y < n && grid[x][y] != 'T');
}
int main(int argc, const char * argv[]) {
ios::sync_with_stdio(0); cin.tie(0);
fill(filltime[0], filltime[0] + 500*500, INT_MAX);
if(2 >= INT_MAX) cout << "Error\n";
cin >> n >> s;
for(int i = 0; i < n; ++i){
string str;
cin >> str;
grid.pb(s);
for(int j = 0; j < str.length(); ++j){
if (str[j] == 'M') b = make_pair(i, j);
if (str[j] == 'D') home = make_pair(i, j);
if(str[j] == 'H'){
hives.push(make_pair(i, j));
filltime[i][j] = 0;
}
}
}
while(!hives.empty()){
pii bee = hives.front();
hives.pop();
int x,y;
x = bee.fi; y = bee.se;
for(int i = 0; i < 4; ++i){
if(!inside(x + dx[i], y + dy[i]) || grid[x+dx[i]][y+dy[i]] == 'D') continue;
if(filltime[x+dx[i]][y+dy[i]] != INT_MAX)
filltime[x+dx[i]][y+dy[i]] = min(filltime[x+dx[i]][y+dy[i]], filltime[x][y] + 1);
else {
filltime[x+dx[i]][y+dy[i]] = filltime[x][y] + 1;
hives.push(make_pair(x + dx[i], y + dy[i]));
}
}
}
int lo = 0, hi = filltime[b.fi][b.se];
int ans = 0;
while(lo < hi){
queue<tuple<int, int, int, int>> q;
int tempans = lo + (hi-lo)/2;
bool pos = false;
fill(visited[0], visited[0] + 500*500, 0);
visited[b.fi][b.se] = 1;
q.push(make_tuple(b.fi, b.se, tempans, 0));
// cout << "New Round " << tempans << '\n';
while(!q.empty()){
tuple<int, int, int, int> cur = q.front();
q.pop();
int x = get<0>(cur);
int y = get<1> (cur);
int a = get<2> (cur);
int res = get<3> (cur);
//cout << x << ' ' << y << ' ' << a << ' ' << res << ' ' << q.size() << ' ' << filltime[x][y] << '\n';
if(a + (double)res/s >= filltime[x][y]) continue;
if(x == home.fi && y == home.se) {
pos = true;
// cout << "Success!\n";
break;
}
int x1, y1;
if(res == s-1) {
y1 = 0;
x1 = a + 1;
} else {
x1 = a;
y1 = res + 1;
}
for(int i = 0; i < 4; ++i) {
if(!inside(x+dx[i],y+dy[i])) continue;
if(visited[x+dx[i]][y+dy[i]]) continue;
visited[x+dx[i]][y+dy[i]] = 1;
q.push(make_tuple(x+dx[i], y+dy[i], x1, y1));
}
}
// cout << pos << '\n';
if(pos) {
ans = max(ans, tempans);
lo = tempans + 1;
} else {
hi = tempans;
}
}
cout << ans << '\n';
return 0;
}
Compilation message
mecho.cpp: In function 'int main(int, const char**)':
mecho.cpp:40:18: error: no matching function for call to 'std::vector<std::__cxx11::basic_string<char> >::push_back(int&)'
40 | grid.pb(s);
| ^
In file included from /usr/include/c++/10/vector:67,
from /usr/include/c++/10/queue:61,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
from mecho.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; std::vector<_Tp, _Alloc>::value_type = std::__cxx11::basic_string<char>]'
1187 | push_back(const value_type& __x)
| ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note: no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const std::__cxx11::basic_string<char>&'}
1187 | push_back(const value_type& __x)
| ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; std::vector<_Tp, _Alloc>::value_type = std::__cxx11::basic_string<char>]'
1203 | push_back(value_type&& __x)
| ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note: no known conversion for argument 1 from 'int' to 'std::vector<std::__cxx11::basic_string<char> >::value_type&&' {aka 'std::__cxx11::basic_string<char>&&'}
1203 | push_back(value_type&& __x)
| ~~~~~~~~~~~~~^~~
mecho.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int j = 0; j < str.length(); ++j){
| ~~^~~~~~~~~~~~~~