# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
442190 |
2021-07-07T09:12:34 Z |
Haidara |
Mecho (IOI09_mecho) |
C++17 |
|
623 ms |
12324 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<<60LL;
const int mod=1e9+7;
const int maxn=808;
int n,foot;
pii Mecho,House;
char a[maxn][maxn];
bool vis[maxn][maxn];
queue<pii>q;
v(v(int)) dist;
int dx[] {-1,1,0,0};
int dy[] {0,0,-1,1};
bool valid(int x,int y)
{
return x>=0&&y>=0&&x<n&&y<n&&a[x][y]=='G';
}
bool nvalid(int x,int y)
{
return x>=0&&y>=0&&x<n&&y<n;
}
bool check(int Time)
{
v(v(int))newdist;
newdist=dist;
FOR(i,maxn)
FOR(j,maxn)
{
vis[i][j]=0;
if(a[i][j]=='T'||a[i][j]=='H'||a[i][j]=='M')
vis[i][j]=1;
}
queue<p(pii,int)>nq;
nq.push({Mecho,foot});
newdist[Mecho.ff][Mecho.ss]=Time;
while(nq.size())
{
pii f=nq.front().ff;
int lft=nq.front().ss;
nq.pop();
FOR(i,4)
{
int x=f.ff+dx[i],y=f.ss+dy[i];
if(nvalid(x,y)&&(a[x][y]=='G'||a[x][y]=='D'))
{
if(!vis[x][y])
{
if(lft)
{
if(newdist[x][y]>newdist[f.ff][f.ss])
{
newdist[x][y]=newdist[f.ff][f.ss];
nq.push({{x,y},lft-1});
vis[x][y]=1;
}
}
else
{
if(newdist[x][y]>newdist[f.ff][f.ss]+1)
{
newdist[x][y]=newdist[f.ff][f.ss]+1;
nq.push({{x,y},foot});
vis[x][y]=1;
}
}
}
}
}
}
return newdist[House.ff][House.ss]!=inf;
}
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(valid(x,y))
{
if(!vis[x][y])
{
vis[x][y]=1;
q.push({x,y});
dist[x][y]=dist[f.ff][f.ss]+1;
}
else if(dist[x][y]>dist[f.ff][f.ss]+1)
{
dist[x][y]=dist[f.ff][f.ss]+1;
q.push({x,y});
}
}
}
}
}
signed main()
{
SIO("");
cin>>n>>foot;
dist.resize(maxn);
FOR(i,maxn)
dist[i].resize(maxn);
FOR(i,n)
FOR(j,n)
{
cin>>a[i][j];
dist[i][j]=inf;
if(a[i][j]=='M')
Mecho= {i,j};
else if(a[i][j]=='H')
q.push({i,j}),vis[i][j]=1,dist[i][j]=0;
else if(a[i][j]=='T')
vis[i][j]=1;
else if(a[i][j]=='D')
House={i,j};
}
solve();
int l=1,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 |
117 ms |
11212 KB |
Output isn't correct |
2 |
Incorrect |
112 ms |
11120 KB |
Output isn't correct |
3 |
Incorrect |
108 ms |
11212 KB |
Output isn't correct |
4 |
Incorrect |
109 ms |
11212 KB |
Output isn't correct |
5 |
Incorrect |
116 ms |
11212 KB |
Output isn't correct |
6 |
Incorrect |
126 ms |
11212 KB |
Output isn't correct |
7 |
Incorrect |
367 ms |
12028 KB |
Output isn't correct |
8 |
Incorrect |
112 ms |
11212 KB |
Output isn't correct |
9 |
Correct |
115 ms |
11212 KB |
Output is correct |
10 |
Incorrect |
112 ms |
11224 KB |
Output isn't correct |
11 |
Incorrect |
113 ms |
11212 KB |
Output isn't correct |
12 |
Incorrect |
118 ms |
11212 KB |
Output isn't correct |
13 |
Incorrect |
216 ms |
11336 KB |
Output isn't correct |
14 |
Incorrect |
204 ms |
11320 KB |
Output isn't correct |
15 |
Incorrect |
115 ms |
11212 KB |
Output isn't correct |
16 |
Correct |
115 ms |
11212 KB |
Output is correct |
17 |
Incorrect |
122 ms |
11220 KB |
Output isn't correct |
18 |
Correct |
114 ms |
11212 KB |
Output is correct |
19 |
Incorrect |
120 ms |
11212 KB |
Output isn't correct |
20 |
Correct |
117 ms |
11216 KB |
Output is correct |
21 |
Incorrect |
118 ms |
11212 KB |
Output isn't correct |
22 |
Correct |
109 ms |
11232 KB |
Output is correct |
23 |
Incorrect |
109 ms |
11252 KB |
Output isn't correct |
24 |
Correct |
132 ms |
11168 KB |
Output is correct |
25 |
Incorrect |
110 ms |
11244 KB |
Output isn't correct |
26 |
Correct |
108 ms |
11212 KB |
Output is correct |
27 |
Incorrect |
118 ms |
11248 KB |
Output isn't correct |
28 |
Correct |
118 ms |
11212 KB |
Output is correct |
29 |
Incorrect |
127 ms |
11212 KB |
Output isn't correct |
30 |
Correct |
110 ms |
11248 KB |
Output is correct |
31 |
Incorrect |
114 ms |
11212 KB |
Output isn't correct |
32 |
Correct |
131 ms |
11260 KB |
Output is correct |
33 |
Incorrect |
123 ms |
11472 KB |
Output isn't correct |
34 |
Correct |
120 ms |
11468 KB |
Output is correct |
35 |
Correct |
232 ms |
11608 KB |
Output is correct |
36 |
Incorrect |
148 ms |
11508 KB |
Output isn't correct |
37 |
Correct |
130 ms |
11512 KB |
Output is correct |
38 |
Correct |
249 ms |
11632 KB |
Output is correct |
39 |
Incorrect |
132 ms |
11676 KB |
Output isn't correct |
40 |
Correct |
133 ms |
11548 KB |
Output is correct |
41 |
Correct |
264 ms |
11648 KB |
Output is correct |
42 |
Incorrect |
141 ms |
11596 KB |
Output isn't correct |
43 |
Correct |
144 ms |
11764 KB |
Output is correct |
44 |
Correct |
270 ms |
11716 KB |
Output is correct |
45 |
Incorrect |
140 ms |
11564 KB |
Output isn't correct |
46 |
Correct |
143 ms |
11816 KB |
Output is correct |
47 |
Correct |
297 ms |
11828 KB |
Output is correct |
48 |
Incorrect |
138 ms |
11676 KB |
Output isn't correct |
49 |
Correct |
140 ms |
11676 KB |
Output is correct |
50 |
Correct |
318 ms |
11748 KB |
Output is correct |
51 |
Incorrect |
166 ms |
11704 KB |
Output isn't correct |
52 |
Correct |
147 ms |
11628 KB |
Output is correct |
53 |
Correct |
352 ms |
12028 KB |
Output is correct |
54 |
Incorrect |
159 ms |
11652 KB |
Output isn't correct |
55 |
Correct |
162 ms |
11748 KB |
Output is correct |
56 |
Correct |
395 ms |
11988 KB |
Output is correct |
57 |
Incorrect |
176 ms |
11672 KB |
Output isn't correct |
58 |
Correct |
167 ms |
11756 KB |
Output is correct |
59 |
Correct |
424 ms |
11980 KB |
Output is correct |
60 |
Incorrect |
165 ms |
11828 KB |
Output isn't correct |
61 |
Correct |
168 ms |
11732 KB |
Output is correct |
62 |
Correct |
436 ms |
12012 KB |
Output is correct |
63 |
Incorrect |
566 ms |
11892 KB |
Output isn't correct |
64 |
Correct |
623 ms |
11888 KB |
Output is correct |
65 |
Incorrect |
595 ms |
12020 KB |
Output isn't correct |
66 |
Incorrect |
554 ms |
11952 KB |
Output isn't correct |
67 |
Incorrect |
555 ms |
11908 KB |
Output isn't correct |
68 |
Incorrect |
482 ms |
11924 KB |
Output isn't correct |
69 |
Correct |
475 ms |
11928 KB |
Output is correct |
70 |
Incorrect |
459 ms |
11848 KB |
Output isn't correct |
71 |
Incorrect |
457 ms |
12284 KB |
Output isn't correct |
72 |
Incorrect |
460 ms |
11872 KB |
Output isn't correct |
73 |
Incorrect |
383 ms |
12112 KB |
Output isn't correct |
74 |
Correct |
318 ms |
11932 KB |
Output is correct |
75 |
Incorrect |
336 ms |
12040 KB |
Output isn't correct |
76 |
Incorrect |
322 ms |
11932 KB |
Output isn't correct |
77 |
Incorrect |
348 ms |
12324 KB |
Output isn't correct |
78 |
Incorrect |
355 ms |
11936 KB |
Output isn't correct |
79 |
Correct |
321 ms |
11960 KB |
Output is correct |
80 |
Incorrect |
319 ms |
11960 KB |
Output isn't correct |
81 |
Incorrect |
335 ms |
12020 KB |
Output isn't correct |
82 |
Incorrect |
360 ms |
12096 KB |
Output isn't correct |
83 |
Incorrect |
353 ms |
11948 KB |
Output isn't correct |
84 |
Correct |
357 ms |
12232 KB |
Output is correct |
85 |
Incorrect |
353 ms |
12024 KB |
Output isn't correct |
86 |
Incorrect |
384 ms |
12092 KB |
Output isn't correct |
87 |
Correct |
379 ms |
11980 KB |
Output is correct |
88 |
Incorrect |
377 ms |
12004 KB |
Output isn't correct |
89 |
Correct |
388 ms |
11924 KB |
Output is correct |
90 |
Correct |
382 ms |
12136 KB |
Output is correct |
91 |
Correct |
441 ms |
11924 KB |
Output is correct |
92 |
Incorrect |
363 ms |
12160 KB |
Output isn't correct |