# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883235 | Servant_of_the_Lord | Mecho (IOI09_mecho) | C++17 | 370 ms | 1316 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll short
using namespace std;
main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll x,y,z,a,b,c,d,e;
cin>>x>>y;
vector<string>v;
vector<vector<ll>>w,u;
for(ll i=0;i<x;i++)
{
string s;
cin>>s;
v.push_back(s);
for(ll j=0;j<x;j++)
{
if(v[i][j]=='M')w.push_back({i,j});
if(v[i][j]=='H')u.push_back({i,j});
}
}
a=0,b=x*x;
while(a<b)
{
ll m=a+(b-a+1)/2;
bool o=false;
vector<vector<ll>>q,r;
vector<vector<bool>>t(x,vector<bool>(x)),s(x,vector<bool>(x));
function<void()>bees=[&]()
{
vector<vector<ll>>q2;
function<void(ll,ll)>ba=[&](ll a,ll b)
{
if(a>=0&&a<x&&b>=0&&b<x&&!t[a][b]&&(v[a][b]=='G'||v[a][b]=='M'))
{
q2.push_back({a,b});
t[a][b]=true;
}
};
for(ll i=0;i<q.size();i++)
{
ba(q[i][0]-1,q[i][1]);
ba(q[i][0]+1,q[i][1]);
ba(q[i][0],q[i][1]-1);
ba(q[i][0],q[i][1]+1);
}
q2.swap(q);
};
function<void()>bear=[&]()
{
vector<vector<ll>>r2;
function<void(ll,ll)>ba=[&](ll a,ll b)
{
if(a>=0&&a<x&&b>=0&&b<x&&!t[a][b]&&!s[a][b]&&(v[a][b]=='G'||v[a][b]=='D'))
{
r2.push_back({a,b});
s[a][b]=true;
if(v[a][b]=='D')o=true;
}
};
for(ll i=0;i<r.size();i++)
{
if(t[r[i][0]][r[i][1]])continue;
ba(r[i][0]-1,r[i][1]);
ba(r[i][0]+1,r[i][1]);
ba(r[i][0],r[i][1]-1);
ba(r[i][0],r[i][1]+1);
}
r2.swap(r);
};
for(auto i:w)r.push_back(i);
for(auto i:u)q.push_back(i);
for(ll i=0;i<m;i++)
{
bees();
if(q.empty())break;
}
while(r.size())
{
for(ll i=0;i<y;i++)bear();
bees();
}
if(o)a=m;
else b=m-1;
}
cout<<a<<'\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |