# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870687 | Servant_of_the_Lord | Tracks in the Snow (BOI13_tracks) | C++17 | 804 ms | 54556 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 long long
using namespace std;
main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll x,y,z,a,b,c;
cin>>x>>y;
vector<string>v;
vector<vector<bool>>w;
for(ll i=0;i<x;i++)w.push_back(vector<bool>(y));
for(ll i=0;i<x;i++)
{
string s;
cin>>s;
v.push_back(s);
}
queue<pair<ll,ll>>q,r;
q.push({0,0});
a=0;
function<void(ll,ll,ll,ll)>add=[&](ll a,ll b,ll c,ll d)
{
if(a>=0&&a<x&&b>=0&&b<y&&!w[a][b])
{
w[a][b]=true;
if(v[a][b]==v[c][d])q.push({a,b});
else if(v[a][b]!='.')r.push({a,b});
}
};
while(q.size())
{
a++;
while(q.size())
{
pair<ll,ll>p=q.front();
add(p.first-1,p.second,p.first,p.second);
add(p.first+1,p.second,p.first,p.second);
add(p.first,p.second-1,p.first,p.second);
add(p.first,p.second+1,p.first,p.second);
q.pop();
}
q.swap(r);
}
cout<<a<<'\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |