# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
533471 |
2022-03-06T06:13:11 Z |
Stro256 |
Mecho (IOI09_mecho) |
C++14 |
|
190 ms |
6364 KB |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define REP(a) F0R(_,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rsz resize
#define pb push_back
#define f first
#define s second
#define pf push_front
#define ft front()
#define bk back()
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define tcT template<class T
#define tcTU tcT, class U
#define nl "\n"
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using str = string;
using vs = vector<str>;
using db = long double;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
tcTU> using PR = pair<T,U>;
const int MOD = 1e9+7;
const ll INF = 1e18;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1};
constexpr int bits(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }
constexpr bool onbit(int msk, int i) { return msk>>i&1; }
constexpr ll p2(int x) { return 1LL<<x; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int lg2(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }; //int only
tcT> bool ckmin(T&a, const T&b) { return b < a ? a = b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) { return b > a ? a = b,1 : 0; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); }
tcTU> T fstTrue(T lo, T hi, U f) {
hi++; assert(lo <= hi);
while (lo < hi) {
T mid = lo+(hi-lo)/2;
f(mid) ? hi = mid : lo = mid+1;
}
return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
lo--; assert(lo <= hi);
while (lo < hi) {
T mid = lo+(hi-lo+1)/2;
f(mid) ? lo = mid : hi = mid-1;
}
return lo;
}
tcT> void remDup(V<T> &v) {
sort(all(v)); v.erase(unique(all(v)), end(v)); }
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if(sizeof...(t)) cerr << ", ";
DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL
void setPrec() { cout << fixed << setprecision(16); }
void setIO(string NAME = "") {
cin.tie(0)->sync_with_stdio(0);
setPrec();
if(sz(NAME)) {
freopen((NAME + ".inp").c_str(),"r",stdin);
freopen((NAME + ".out").c_str(),"w",stdout);
}
}
const int MX = 805;
int N, S, si, sj, ei, ej;
str g[MX];
int d[MX][MX], d1[MX][MX];
bool isInside(int x, int y) {
return min(x,y)>=0 && max(x,y)<N;
}
void bfs(int dis[MX][MX], int st) {
queue<pi> q;
F0R(i,N) F0R(j,N) if(!dis[i][j]) q.push({i,j});
while(!q.empty()) {
int x = q.ft.f, y = q.ft.s; q.pop();
if(st>=0 && dis[x][y]/S + st >= d1[x][y]) continue;
F0R(i,4) {
int nx = x + dx[i], ny = y + dy[i];
if(isInside(nx, ny) && (g[nx][ny]!='T') && (st>=0 || g[nx][ny] != 'D') && dis[nx][ny]>=MOD) {
q.push({nx, ny});
dis[nx][ny] = dis[x][y] + 1;
}
}
}
}
void solve() {
cin>>N>>S;
F0R(i,N) cin>>g[i];
memset(d1, 0x3f, sizeof d1);
F0R(i,N) F0R(j,N) {
if(g[i][j] == 'M') {
si = i, sj = j;
}
else if(g[i][j] == 'H') {
d1[i][j] = 0;
}
else if(g[i][j] == 'D') {
ei = i, ej = j;
}
}
bfs(d1, -1);
int lo = -1, hi = N*N+1;
while(lo<hi) {
int mid = lo + (hi-lo+1)/2;
memset(d, 0x3f, sizeof d);
d[si][sj] = 0;
bfs(d, mid);
if(d[ei][ej] < MOD) lo = mid;
else hi = mid-1;
}
cout << lo << nl;
}
int main() {
setIO();
int t=1;
//cin>>t;
while(t-->0) {
solve();
}
return 0;
}
Compilation message
mecho.cpp: In function 'void setIO(std::string)':
mecho.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | freopen((NAME + ".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen((NAME + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5324 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5300 KB |
Output is correct |
4 |
Correct |
3 ms |
5324 KB |
Output is correct |
5 |
Correct |
4 ms |
5324 KB |
Output is correct |
6 |
Correct |
4 ms |
5324 KB |
Output is correct |
7 |
Correct |
83 ms |
6176 KB |
Output is correct |
8 |
Correct |
3 ms |
5324 KB |
Output is correct |
9 |
Correct |
3 ms |
5324 KB |
Output is correct |
10 |
Correct |
3 ms |
5324 KB |
Output is correct |
11 |
Correct |
3 ms |
5324 KB |
Output is correct |
12 |
Correct |
3 ms |
5324 KB |
Output is correct |
13 |
Correct |
3 ms |
5324 KB |
Output is correct |
14 |
Correct |
3 ms |
5400 KB |
Output is correct |
15 |
Correct |
3 ms |
5324 KB |
Output is correct |
16 |
Correct |
3 ms |
5324 KB |
Output is correct |
17 |
Correct |
3 ms |
5324 KB |
Output is correct |
18 |
Correct |
3 ms |
5324 KB |
Output is correct |
19 |
Correct |
3 ms |
5324 KB |
Output is correct |
20 |
Correct |
4 ms |
5324 KB |
Output is correct |
21 |
Correct |
3 ms |
5324 KB |
Output is correct |
22 |
Correct |
3 ms |
5352 KB |
Output is correct |
23 |
Correct |
4 ms |
5324 KB |
Output is correct |
24 |
Correct |
4 ms |
5392 KB |
Output is correct |
25 |
Correct |
5 ms |
5324 KB |
Output is correct |
26 |
Correct |
3 ms |
5324 KB |
Output is correct |
27 |
Correct |
3 ms |
5324 KB |
Output is correct |
28 |
Correct |
3 ms |
5324 KB |
Output is correct |
29 |
Correct |
3 ms |
5324 KB |
Output is correct |
30 |
Correct |
3 ms |
5324 KB |
Output is correct |
31 |
Correct |
3 ms |
5324 KB |
Output is correct |
32 |
Correct |
4 ms |
5324 KB |
Output is correct |
33 |
Correct |
7 ms |
5452 KB |
Output is correct |
34 |
Correct |
7 ms |
5540 KB |
Output is correct |
35 |
Correct |
21 ms |
5452 KB |
Output is correct |
36 |
Correct |
8 ms |
5580 KB |
Output is correct |
37 |
Correct |
8 ms |
5580 KB |
Output is correct |
38 |
Correct |
27 ms |
5580 KB |
Output is correct |
39 |
Correct |
9 ms |
5580 KB |
Output is correct |
40 |
Correct |
15 ms |
5580 KB |
Output is correct |
41 |
Correct |
38 ms |
5580 KB |
Output is correct |
42 |
Correct |
10 ms |
5580 KB |
Output is correct |
43 |
Correct |
10 ms |
5672 KB |
Output is correct |
44 |
Correct |
43 ms |
5584 KB |
Output is correct |
45 |
Correct |
12 ms |
5628 KB |
Output is correct |
46 |
Correct |
12 ms |
5704 KB |
Output is correct |
47 |
Correct |
51 ms |
5756 KB |
Output is correct |
48 |
Correct |
15 ms |
5708 KB |
Output is correct |
49 |
Correct |
21 ms |
5708 KB |
Output is correct |
50 |
Correct |
70 ms |
5708 KB |
Output is correct |
51 |
Correct |
15 ms |
5856 KB |
Output is correct |
52 |
Correct |
15 ms |
5836 KB |
Output is correct |
53 |
Correct |
69 ms |
5844 KB |
Output is correct |
54 |
Correct |
18 ms |
5820 KB |
Output is correct |
55 |
Correct |
24 ms |
5928 KB |
Output is correct |
56 |
Correct |
106 ms |
5920 KB |
Output is correct |
57 |
Correct |
19 ms |
5964 KB |
Output is correct |
58 |
Correct |
21 ms |
6004 KB |
Output is correct |
59 |
Correct |
113 ms |
5912 KB |
Output is correct |
60 |
Correct |
22 ms |
6080 KB |
Output is correct |
61 |
Correct |
22 ms |
5980 KB |
Output is correct |
62 |
Correct |
113 ms |
5964 KB |
Output is correct |
63 |
Correct |
100 ms |
5984 KB |
Output is correct |
64 |
Correct |
190 ms |
6108 KB |
Output is correct |
65 |
Correct |
145 ms |
6064 KB |
Output is correct |
66 |
Correct |
113 ms |
5956 KB |
Output is correct |
67 |
Correct |
109 ms |
5988 KB |
Output is correct |
68 |
Correct |
50 ms |
6028 KB |
Output is correct |
69 |
Correct |
45 ms |
6092 KB |
Output is correct |
70 |
Correct |
42 ms |
6008 KB |
Output is correct |
71 |
Correct |
43 ms |
6008 KB |
Output is correct |
72 |
Correct |
31 ms |
6092 KB |
Output is correct |
73 |
Correct |
30 ms |
6348 KB |
Output is correct |
74 |
Correct |
53 ms |
6348 KB |
Output is correct |
75 |
Correct |
67 ms |
6336 KB |
Output is correct |
76 |
Correct |
57 ms |
6340 KB |
Output is correct |
77 |
Correct |
68 ms |
6364 KB |
Output is correct |
78 |
Correct |
67 ms |
6308 KB |
Output is correct |
79 |
Correct |
46 ms |
6312 KB |
Output is correct |
80 |
Correct |
73 ms |
6216 KB |
Output is correct |
81 |
Correct |
65 ms |
6244 KB |
Output is correct |
82 |
Correct |
55 ms |
6240 KB |
Output is correct |
83 |
Correct |
70 ms |
6272 KB |
Output is correct |
84 |
Correct |
72 ms |
6220 KB |
Output is correct |
85 |
Correct |
76 ms |
6276 KB |
Output is correct |
86 |
Correct |
69 ms |
6220 KB |
Output is correct |
87 |
Correct |
74 ms |
6284 KB |
Output is correct |
88 |
Correct |
77 ms |
6228 KB |
Output is correct |
89 |
Correct |
80 ms |
6144 KB |
Output is correct |
90 |
Correct |
78 ms |
6220 KB |
Output is correct |
91 |
Correct |
78 ms |
6228 KB |
Output is correct |
92 |
Correct |
85 ms |
6220 KB |
Output is correct |