# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
554997 |
2022-04-29T19:52:25 Z |
savackexp |
Mecho (IOI09_mecho) |
C++14 |
|
1000 ms |
16812 KB |
#include<bits/stdc++.h>
using namespace std;
#define in insert
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define Endl "\n"
#define ENDL "\n"
#define fi first
#define se second
#define be begin()
#define en end()
#define pb push_back
typedef long long ll;
typedef long double ld;
const int MOD=1e9+7;
const int MAX=2e5+1;/*
ll binpow(ll a, ll b) {
ld res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
unsigned long long power(unsigned long long x,
ll y, ll p)
{
unsigned long long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
unsigned long long modInverse(unsigned long long n,
ll p)
{
return power(n, p - 2, p);
}
*/
ll n , k ;
ll dx[]={0 , 0 , 1, -1};
ll dy[]={1 , -1 , 0, 0};
char grid[805][805];
ll vis[805][805];
ll levelm[805][805];
ll levelh[805][805];
vector<pair<ll,ll>>hive;
bool valid(ll x , ll y)
{
return x>=0 && y>=0 && x<n && y<n && grid[x][y]!='H' && grid[x][y]!='T';
}
bool valid1(ll x , ll y)
{
return x>=0 && y>=0 && x<n && y<n && grid[x][y]!='T' && grid[x][y]!='D' && grid[x][y]!='M';
}
pair<ll,ll>m , d;
bool check(ll u)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
levelm[i][j]=1e18;
}
}
memset(vis , 0 ,sizeof vis );
queue< pair<ll,ll> >q;
q.push({m.fi,m.se});
vis[m.fi][m.se]=1;
levelm[m.fi][m.se]=0;
while(!q.empty())
{
pair<ll,ll>p=q.front();
q.pop();
for(int i=0;i<4;i++)
{
ll nx = p.fi + dx[i];
ll ny = p.se + dy[i];
if(!valid(nx,ny))continue;
levelm[nx][ny]=min(levelm[p.fi][p.se]+1 ,levelm[nx][ny] + u);
ll qe = (levelm[nx][ny])/k;
if(levelh[nx][ny] <= qe)continue;
if(vis[nx][ny])continue;
vis[nx][ny] = 1;
q.push({nx , ny});
}
}
if(levelm[d.fi][d.se] != 1e18)
{
return true;
}
return false;
}
void bfs(vector<pair<ll,ll>>h)
{
queue<pair<ll,ll> >q;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
levelh[i][j]=1e18;
}
}
for(int i=0;i<h.size();i++)
{
levelh[h[i].fi][h[i].se]=0;
vis[h[i].fi][h[i].se]=1;
q.push(h[i]);
}
while(!q.empty())
{
pair<ll,ll>p=q.front();
q.pop();
for(int i=0;i<4;i++)
{
ll nx = p.fi + dx[i];
ll ny = p.se + dy[i];
if(!valid1(nx,ny))continue;
levelh[nx][ny] = min(levelh[p.fi][p.se]+1 ,levelh[nx][ny]);
if(vis[nx][ny])continue;
vis[nx][ny] = 1;
q.push({nx , ny});
}
}
}
int main()
{
fastio
//freopen("gravity.in","r",stdin);
//freopen("gravity.out","w",stdout);
cin>>n>>k;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
for(int j=0;j<s.size();j++)
{
grid[i][j]=s[j];
if(s[j]=='H')hive.pb({i,j});
else if(s[j]=='M')m={i,j};
else if(s[j]=='D')d={i,j};
}
}
bfs(hive);
memset(vis , 0 ,sizeof vis);
ll l=0;
ll r=1e18;
ll ans=-1;
while(l<=r)
{
ll mid=(l+r)/2;
if(check(mid))
{
ans=mid;
l=mid+1;
}
else r=mid-1;
}
cout<<ans<<endl;
return 0;
}
/*
5 6
0 4 0
0 3 1
0 1 1
0 2 1
1 2 1
3 4 0
*/
Compilation message
mecho.cpp: In function 'void bfs(std::vector<std::pair<long long int, long long int> >)':
mecho.cpp:124:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int i=0;i<h.size();i++)
| ~^~~~~~~~~
mecho.cpp: In function 'int main()':
mecho.cpp:166:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
166 | for(int j=0;j<s.size();j++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
5332 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
5332 KB |
Output isn't correct |
3 |
Incorrect |
14 ms |
5444 KB |
Output isn't correct |
4 |
Incorrect |
12 ms |
5456 KB |
Output isn't correct |
5 |
Incorrect |
12 ms |
5460 KB |
Output isn't correct |
6 |
Incorrect |
12 ms |
5496 KB |
Output isn't correct |
7 |
Execution timed out |
1088 ms |
16308 KB |
Time limit exceeded |
8 |
Correct |
10 ms |
5460 KB |
Output is correct |
9 |
Incorrect |
12 ms |
5540 KB |
Output isn't correct |
10 |
Incorrect |
10 ms |
5540 KB |
Output isn't correct |
11 |
Incorrect |
12 ms |
5460 KB |
Output isn't correct |
12 |
Incorrect |
11 ms |
5972 KB |
Output isn't correct |
13 |
Incorrect |
15 ms |
5844 KB |
Output isn't correct |
14 |
Correct |
14 ms |
6004 KB |
Output is correct |
15 |
Incorrect |
14 ms |
5520 KB |
Output isn't correct |
16 |
Incorrect |
11 ms |
5588 KB |
Output isn't correct |
17 |
Incorrect |
11 ms |
5636 KB |
Output isn't correct |
18 |
Incorrect |
12 ms |
5644 KB |
Output isn't correct |
19 |
Incorrect |
12 ms |
5588 KB |
Output isn't correct |
20 |
Incorrect |
12 ms |
5700 KB |
Output isn't correct |
21 |
Incorrect |
13 ms |
5716 KB |
Output isn't correct |
22 |
Incorrect |
12 ms |
5800 KB |
Output isn't correct |
23 |
Incorrect |
12 ms |
5844 KB |
Output isn't correct |
24 |
Incorrect |
14 ms |
5904 KB |
Output isn't correct |
25 |
Incorrect |
13 ms |
5972 KB |
Output isn't correct |
26 |
Incorrect |
15 ms |
5972 KB |
Output isn't correct |
27 |
Incorrect |
14 ms |
6044 KB |
Output isn't correct |
28 |
Incorrect |
18 ms |
6048 KB |
Output isn't correct |
29 |
Incorrect |
14 ms |
6108 KB |
Output isn't correct |
30 |
Incorrect |
15 ms |
6096 KB |
Output isn't correct |
31 |
Incorrect |
18 ms |
6148 KB |
Output isn't correct |
32 |
Incorrect |
16 ms |
6148 KB |
Output isn't correct |
33 |
Incorrect |
83 ms |
10084 KB |
Output isn't correct |
34 |
Incorrect |
114 ms |
10004 KB |
Output isn't correct |
35 |
Incorrect |
221 ms |
10068 KB |
Output isn't correct |
36 |
Incorrect |
101 ms |
10740 KB |
Output isn't correct |
37 |
Incorrect |
145 ms |
10756 KB |
Output isn't correct |
38 |
Incorrect |
288 ms |
10768 KB |
Output isn't correct |
39 |
Incorrect |
126 ms |
11348 KB |
Output isn't correct |
40 |
Incorrect |
184 ms |
11432 KB |
Output isn't correct |
41 |
Incorrect |
396 ms |
11432 KB |
Output isn't correct |
42 |
Incorrect |
158 ms |
11988 KB |
Output isn't correct |
43 |
Incorrect |
219 ms |
11988 KB |
Output isn't correct |
44 |
Incorrect |
472 ms |
12116 KB |
Output isn't correct |
45 |
Incorrect |
175 ms |
12780 KB |
Output isn't correct |
46 |
Incorrect |
259 ms |
12788 KB |
Output isn't correct |
47 |
Incorrect |
624 ms |
12784 KB |
Output isn't correct |
48 |
Incorrect |
214 ms |
13396 KB |
Output isn't correct |
49 |
Incorrect |
290 ms |
13452 KB |
Output isn't correct |
50 |
Incorrect |
723 ms |
13464 KB |
Output isn't correct |
51 |
Incorrect |
247 ms |
14036 KB |
Output isn't correct |
52 |
Incorrect |
384 ms |
14124 KB |
Output isn't correct |
53 |
Incorrect |
886 ms |
14132 KB |
Output isn't correct |
54 |
Incorrect |
268 ms |
14788 KB |
Output isn't correct |
55 |
Incorrect |
396 ms |
14780 KB |
Output isn't correct |
56 |
Execution timed out |
1032 ms |
14796 KB |
Time limit exceeded |
57 |
Incorrect |
307 ms |
15456 KB |
Output isn't correct |
58 |
Incorrect |
449 ms |
15444 KB |
Output isn't correct |
59 |
Execution timed out |
1080 ms |
15380 KB |
Time limit exceeded |
60 |
Incorrect |
348 ms |
16204 KB |
Output isn't correct |
61 |
Incorrect |
501 ms |
16124 KB |
Output isn't correct |
62 |
Execution timed out |
1096 ms |
16076 KB |
Time limit exceeded |
63 |
Execution timed out |
1091 ms |
16084 KB |
Time limit exceeded |
64 |
Execution timed out |
1084 ms |
16072 KB |
Time limit exceeded |
65 |
Execution timed out |
1097 ms |
16104 KB |
Time limit exceeded |
66 |
Execution timed out |
1094 ms |
16140 KB |
Time limit exceeded |
67 |
Correct |
703 ms |
16204 KB |
Output is correct |
68 |
Incorrect |
377 ms |
16196 KB |
Output isn't correct |
69 |
Incorrect |
483 ms |
16200 KB |
Output isn't correct |
70 |
Incorrect |
328 ms |
16080 KB |
Output isn't correct |
71 |
Incorrect |
300 ms |
16200 KB |
Output isn't correct |
72 |
Incorrect |
508 ms |
16224 KB |
Output isn't correct |
73 |
Incorrect |
780 ms |
16812 KB |
Output isn't correct |
74 |
Execution timed out |
1089 ms |
16596 KB |
Time limit exceeded |
75 |
Incorrect |
769 ms |
16756 KB |
Output isn't correct |
76 |
Incorrect |
666 ms |
16772 KB |
Output isn't correct |
77 |
Incorrect |
876 ms |
16688 KB |
Output isn't correct |
78 |
Correct |
752 ms |
16588 KB |
Output is correct |
79 |
Execution timed out |
1096 ms |
16608 KB |
Time limit exceeded |
80 |
Incorrect |
773 ms |
16588 KB |
Output isn't correct |
81 |
Incorrect |
724 ms |
16684 KB |
Output isn't correct |
82 |
Incorrect |
837 ms |
16664 KB |
Output isn't correct |
83 |
Incorrect |
934 ms |
16532 KB |
Output isn't correct |
84 |
Execution timed out |
1089 ms |
16544 KB |
Time limit exceeded |
85 |
Execution timed out |
1030 ms |
16596 KB |
Time limit exceeded |
86 |
Incorrect |
973 ms |
16592 KB |
Output isn't correct |
87 |
Execution timed out |
1090 ms |
16584 KB |
Time limit exceeded |
88 |
Execution timed out |
1064 ms |
16432 KB |
Time limit exceeded |
89 |
Execution timed out |
1094 ms |
16444 KB |
Time limit exceeded |
90 |
Execution timed out |
1096 ms |
16440 KB |
Time limit exceeded |
91 |
Execution timed out |
1090 ms |
16540 KB |
Time limit exceeded |
92 |
Execution timed out |
1041 ms |
16472 KB |
Time limit exceeded |