# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
442331 |
2021-07-07T13:10:03 Z |
Haidara |
Mecho (IOI09_mecho) |
C++17 |
|
78 ms |
7136 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=808;
char a[maxn][maxn];
int n,jump;
pii M,D;
queue<pii>q;
int dist[maxn][maxn],dx[] {-1,1,0,0},dy[] {0,0,1,-1};
void solve()
{
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||y<0||x>=n||y>=n||dist[x][y]!=inf||a[x][y]!='G')
continue;
dist[x][y]=dist[f.ff][f.ss]+jump,q.push({x,y});
}
}
}
bool check(int st)
{
queue<p(pii,int)>qq;
if(st*jump>=dist[M.ff][M.ss])
return 0;
bool vis[maxn][maxn];
FOR(i,maxn)
FOR(j,maxn)
vis[i][j]=0;
qq.push({M,st*jump});
vis[M.ff][M.ss]=1;
while(qq.size())
{
pii f=qq.front().ff;
int curr=qq.front().ss;
qq.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'||vis[x][y]||dist[x][y]<=curr+1)
continue;
qq.push({{x,y},curr+1});
vis[x][y]=1;
}
}
return 0;
}
signed main()
{
SIO("");
cin>>n>>jump;
FOR(i,n)
FOR(j,n)
{
dist[i][j]=inf;
cin>>a[i][j];
if(a[i][j]=='M')
M= {i,j};
else if(a[i][j]=='D')
D= {i,j};
else if(a[i][j]=='H')
q.push({i,j}),dist[i][j]=0;
}
solve();
int l=0,r=inf,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 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
7 |
Incorrect |
62 ms |
6808 KB |
Output isn't correct |
8 |
Correct |
3 ms |
972 KB |
Output is correct |
9 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
1000 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
1100 KB |
Output isn't correct |
14 |
Correct |
3 ms |
1228 KB |
Output is correct |
15 |
Incorrect |
3 ms |
972 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
18 |
Incorrect |
3 ms |
972 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
21 |
Incorrect |
3 ms |
1100 KB |
Output isn't correct |
22 |
Incorrect |
3 ms |
1148 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
24 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
25 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
26 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
28 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
29 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
30 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
31 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
32 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
33 |
Incorrect |
12 ms |
3316 KB |
Output isn't correct |
34 |
Incorrect |
12 ms |
3424 KB |
Output isn't correct |
35 |
Incorrect |
16 ms |
3424 KB |
Output isn't correct |
36 |
Incorrect |
15 ms |
3768 KB |
Output isn't correct |
37 |
Incorrect |
15 ms |
3672 KB |
Output isn't correct |
38 |
Incorrect |
16 ms |
3684 KB |
Output isn't correct |
39 |
Incorrect |
20 ms |
4044 KB |
Output isn't correct |
40 |
Incorrect |
21 ms |
4044 KB |
Output isn't correct |
41 |
Incorrect |
20 ms |
4044 KB |
Output isn't correct |
42 |
Incorrect |
22 ms |
4484 KB |
Output isn't correct |
43 |
Incorrect |
21 ms |
4428 KB |
Output isn't correct |
44 |
Incorrect |
25 ms |
4488 KB |
Output isn't correct |
45 |
Incorrect |
26 ms |
4828 KB |
Output isn't correct |
46 |
Incorrect |
28 ms |
4832 KB |
Output isn't correct |
47 |
Incorrect |
31 ms |
4804 KB |
Output isn't correct |
48 |
Incorrect |
31 ms |
5100 KB |
Output isn't correct |
49 |
Incorrect |
30 ms |
5172 KB |
Output isn't correct |
50 |
Incorrect |
34 ms |
5092 KB |
Output isn't correct |
51 |
Incorrect |
37 ms |
5656 KB |
Output isn't correct |
52 |
Incorrect |
35 ms |
5500 KB |
Output isn't correct |
53 |
Incorrect |
41 ms |
5444 KB |
Output isn't correct |
54 |
Incorrect |
42 ms |
5868 KB |
Output isn't correct |
55 |
Incorrect |
40 ms |
5836 KB |
Output isn't correct |
56 |
Incorrect |
47 ms |
5912 KB |
Output isn't correct |
57 |
Incorrect |
46 ms |
6160 KB |
Output isn't correct |
58 |
Incorrect |
48 ms |
6212 KB |
Output isn't correct |
59 |
Incorrect |
54 ms |
6216 KB |
Output isn't correct |
60 |
Incorrect |
53 ms |
6504 KB |
Output isn't correct |
61 |
Incorrect |
53 ms |
6512 KB |
Output isn't correct |
62 |
Incorrect |
59 ms |
6600 KB |
Output isn't correct |
63 |
Incorrect |
64 ms |
6500 KB |
Output isn't correct |
64 |
Incorrect |
62 ms |
6620 KB |
Output isn't correct |
65 |
Incorrect |
61 ms |
6616 KB |
Output isn't correct |
66 |
Incorrect |
62 ms |
6612 KB |
Output isn't correct |
67 |
Correct |
62 ms |
6596 KB |
Output is correct |
68 |
Incorrect |
65 ms |
6556 KB |
Output isn't correct |
69 |
Incorrect |
69 ms |
6560 KB |
Output isn't correct |
70 |
Incorrect |
64 ms |
6596 KB |
Output isn't correct |
71 |
Incorrect |
67 ms |
6568 KB |
Output isn't correct |
72 |
Incorrect |
65 ms |
6604 KB |
Output isn't correct |
73 |
Incorrect |
78 ms |
7108 KB |
Output isn't correct |
74 |
Incorrect |
70 ms |
7136 KB |
Output isn't correct |
75 |
Incorrect |
65 ms |
7092 KB |
Output isn't correct |
76 |
Incorrect |
69 ms |
7048 KB |
Output isn't correct |
77 |
Incorrect |
64 ms |
7108 KB |
Output isn't correct |
78 |
Correct |
68 ms |
7020 KB |
Output is correct |
79 |
Incorrect |
66 ms |
6968 KB |
Output isn't correct |
80 |
Incorrect |
77 ms |
7052 KB |
Output isn't correct |
81 |
Incorrect |
64 ms |
7108 KB |
Output isn't correct |
82 |
Incorrect |
65 ms |
7084 KB |
Output isn't correct |
83 |
Incorrect |
65 ms |
7028 KB |
Output isn't correct |
84 |
Incorrect |
65 ms |
6920 KB |
Output isn't correct |
85 |
Incorrect |
73 ms |
6980 KB |
Output isn't correct |
86 |
Incorrect |
65 ms |
6984 KB |
Output isn't correct |
87 |
Incorrect |
65 ms |
6920 KB |
Output isn't correct |
88 |
Incorrect |
63 ms |
6856 KB |
Output isn't correct |
89 |
Incorrect |
68 ms |
6880 KB |
Output isn't correct |
90 |
Incorrect |
63 ms |
6888 KB |
Output isn't correct |
91 |
Incorrect |
64 ms |
7028 KB |
Output isn't correct |
92 |
Incorrect |
65 ms |
6852 KB |
Output isn't correct |