# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
442342 |
2021-07-07T13:21:21 Z |
Haidara |
Mecho (IOI09_mecho) |
C++17 |
|
241 ms |
14524 KB |
/* * * * * * * * * *\
* Author: Haidara *
* LANG: C++17 *
* PROB: *
\* * * * * * * * * */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define rep(i,x,n) for(int i=x;i<(n);i++)
#define FOR(i,n) rep(i,0,n)
#define per(i,x,n) for(int i=x;i>(n);i--)
#define ROF(i,x) for(int i=x;i>=0;i--)
#define v(i) vector< i >
#define p(i,j) pair< i , j >
#define pii pair<int,int>
#define m(i,j) map< i , j >
#define um(i,j) unordered_map< i , j >
#define pq(i) priority_queue< i >
#define ff first
#define all(x) x.begin(),x.end()
#define ss second
#define pp push_back
using namespace std;
void SIO(string name="")
{
if(name!="")
{
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
}
const int inf=1LL<<62LL;
const int mod=1e9+7;
const int maxn=2002;
char a[maxn][maxn];
int n,jump;
pii M,D;
int dist[maxn][maxn],dx[] {-1,1,0,0},dy[] {0,0,1,-1};
bool check(int st)
{
queue<p(pii,int)>q;
if(st*jump>=dist[M.ff][M.ss])
return 0;
q.push({M,st*jump});
bool vis[maxn][maxn];
FOR(i,maxn)
FOR(j,maxn)
vis[i][j]=0;
vis[M.ff][M.ss]=1;
while(q.size())
{
pii f=q.front().ff;
int curr=q.front().ss;
q.pop();
if(f==D)
return 1;
FOR(i,4)
{
int x=f.ff+dx[i],y=f.ss+dy[i];
if(x<0||y<0||x>=n||y>=n||a[x][y]=='T'||a[x][y]=='H'||dist[x][y]<=curr+1||vis[x][y])
continue;
q.push({{x,y},curr+1}),vis[x][y]=1;
}
}
return 0;
}
signed main()
{
SIO("");
cin>>n>>jump;
queue<pii>q;
FOR(i,n)
{
cin>>ws;
FOR(j,n)
{
dist[i][j]=inf;
cin>>a[i][j];
if(a[i][j]=='M')
M= {i,j},a[i][j]='G';
else if(a[i][j]=='D')
D= {i,j};
else if(a[i][j]=='H')
q.push({i,j}),dist[i][j]=0;
}
}
while(q.size())
{
pii f=q.front();
q.pop();
FOR(i,4)
{
int x=f.ff+dx[i],y=f.ss+dy[i];
if(x<0||x>=n||y<0||y>=n||a[x][y]!='G'||dist[x][y]!=inf)
continue;
dist[x][y]=dist[f.ff][f.ss]+jump;
q.push({x,y});
}
}
int l=1,r=maxn*maxn*2,ans=-1;
while(l<=r)
{
int mid=l+(r-l)/2;
if(check(mid))
ans=max(ans,mid),l=mid+1;
else
r=mid-1;
}
cout<<ans;
}
Compilation message
mecho.cpp: In function 'void SIO(std::string)':
mecho.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4172 KB |
Output is correct |
2 |
Correct |
3 ms |
4172 KB |
Output is correct |
3 |
Correct |
3 ms |
4172 KB |
Output is correct |
4 |
Correct |
3 ms |
4172 KB |
Output is correct |
5 |
Incorrect |
2 ms |
4172 KB |
Output isn't correct |
6 |
Correct |
3 ms |
4172 KB |
Output is correct |
7 |
Correct |
167 ms |
14300 KB |
Output is correct |
8 |
Correct |
3 ms |
4300 KB |
Output is correct |
9 |
Correct |
3 ms |
4300 KB |
Output is correct |
10 |
Correct |
3 ms |
4300 KB |
Output is correct |
11 |
Correct |
3 ms |
4300 KB |
Output is correct |
12 |
Correct |
4 ms |
4556 KB |
Output is correct |
13 |
Incorrect |
3 ms |
4428 KB |
Output isn't correct |
14 |
Correct |
5 ms |
4556 KB |
Output is correct |
15 |
Correct |
4 ms |
4336 KB |
Output is correct |
16 |
Correct |
3 ms |
4300 KB |
Output is correct |
17 |
Correct |
3 ms |
4300 KB |
Output is correct |
18 |
Correct |
3 ms |
4300 KB |
Output is correct |
19 |
Correct |
5 ms |
4300 KB |
Output is correct |
20 |
Correct |
4 ms |
4408 KB |
Output is correct |
21 |
Correct |
3 ms |
4428 KB |
Output is correct |
22 |
Correct |
4 ms |
4476 KB |
Output is correct |
23 |
Correct |
4 ms |
4428 KB |
Output is correct |
24 |
Correct |
4 ms |
4428 KB |
Output is correct |
25 |
Correct |
4 ms |
4556 KB |
Output is correct |
26 |
Correct |
4 ms |
4556 KB |
Output is correct |
27 |
Correct |
4 ms |
4556 KB |
Output is correct |
28 |
Correct |
4 ms |
4556 KB |
Output is correct |
29 |
Correct |
4 ms |
4684 KB |
Output is correct |
30 |
Correct |
4 ms |
4684 KB |
Output is correct |
31 |
Correct |
4 ms |
4684 KB |
Output is correct |
32 |
Correct |
4 ms |
4720 KB |
Output is correct |
33 |
Correct |
14 ms |
7256 KB |
Output is correct |
34 |
Correct |
14 ms |
7204 KB |
Output is correct |
35 |
Correct |
40 ms |
7264 KB |
Output is correct |
36 |
Correct |
17 ms |
7756 KB |
Output is correct |
37 |
Correct |
18 ms |
7820 KB |
Output is correct |
38 |
Correct |
53 ms |
7756 KB |
Output is correct |
39 |
Correct |
20 ms |
8396 KB |
Output is correct |
40 |
Correct |
24 ms |
8456 KB |
Output is correct |
41 |
Correct |
62 ms |
8488 KB |
Output is correct |
42 |
Correct |
25 ms |
9076 KB |
Output is correct |
43 |
Correct |
26 ms |
9084 KB |
Output is correct |
44 |
Correct |
83 ms |
9132 KB |
Output is correct |
45 |
Correct |
30 ms |
9788 KB |
Output is correct |
46 |
Correct |
30 ms |
9744 KB |
Output is correct |
47 |
Correct |
109 ms |
9868 KB |
Output is correct |
48 |
Correct |
33 ms |
10520 KB |
Output is correct |
49 |
Correct |
33 ms |
10588 KB |
Output is correct |
50 |
Correct |
124 ms |
10616 KB |
Output is correct |
51 |
Correct |
40 ms |
11368 KB |
Output is correct |
52 |
Correct |
40 ms |
11368 KB |
Output is correct |
53 |
Correct |
142 ms |
11388 KB |
Output is correct |
54 |
Correct |
44 ms |
12136 KB |
Output is correct |
55 |
Correct |
44 ms |
12188 KB |
Output is correct |
56 |
Correct |
166 ms |
12236 KB |
Output is correct |
57 |
Correct |
48 ms |
12988 KB |
Output is correct |
58 |
Correct |
55 ms |
13040 KB |
Output is correct |
59 |
Correct |
199 ms |
13000 KB |
Output is correct |
60 |
Correct |
56 ms |
13960 KB |
Output is correct |
61 |
Correct |
59 ms |
13876 KB |
Output is correct |
62 |
Correct |
233 ms |
13996 KB |
Output is correct |
63 |
Incorrect |
147 ms |
13944 KB |
Output isn't correct |
64 |
Correct |
238 ms |
13984 KB |
Output is correct |
65 |
Correct |
236 ms |
14180 KB |
Output is correct |
66 |
Correct |
241 ms |
13924 KB |
Output is correct |
67 |
Correct |
168 ms |
13904 KB |
Output is correct |
68 |
Incorrect |
93 ms |
14124 KB |
Output isn't correct |
69 |
Correct |
105 ms |
13952 KB |
Output is correct |
70 |
Correct |
86 ms |
13960 KB |
Output is correct |
71 |
Correct |
76 ms |
14040 KB |
Output is correct |
72 |
Correct |
73 ms |
14020 KB |
Output is correct |
73 |
Correct |
79 ms |
14524 KB |
Output is correct |
74 |
Correct |
118 ms |
14452 KB |
Output is correct |
75 |
Correct |
125 ms |
14524 KB |
Output is correct |
76 |
Correct |
122 ms |
14460 KB |
Output is correct |
77 |
Correct |
121 ms |
14460 KB |
Output is correct |
78 |
Correct |
137 ms |
14492 KB |
Output is correct |
79 |
Correct |
117 ms |
14384 KB |
Output is correct |
80 |
Correct |
126 ms |
14376 KB |
Output is correct |
81 |
Correct |
143 ms |
14472 KB |
Output is correct |
82 |
Correct |
120 ms |
14480 KB |
Output is correct |
83 |
Incorrect |
148 ms |
14320 KB |
Output isn't correct |
84 |
Correct |
162 ms |
14316 KB |
Output is correct |
85 |
Correct |
141 ms |
14400 KB |
Output is correct |
86 |
Correct |
148 ms |
14308 KB |
Output is correct |
87 |
Correct |
144 ms |
14404 KB |
Output is correct |
88 |
Incorrect |
146 ms |
14212 KB |
Output isn't correct |
89 |
Correct |
167 ms |
14268 KB |
Output is correct |
90 |
Correct |
162 ms |
14276 KB |
Output is correct |
91 |
Correct |
158 ms |
14220 KB |
Output is correct |
92 |
Correct |
181 ms |
14304 KB |
Output is correct |