| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 417939 | rumen_m | Miners (IOI07_miners) | C++17 | 1578 ms | 460 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>
using namespace std;
map <pair <int,string > ,int> mp;
priority_queue <pair <int, string> > q;
int query(char a, char b, char c)
{
char v[3];
v[0] = a;
v[1] = b;
v[2] = c;
int ans = 0;
sort(v,v+3);
for(int i=0;i<3;i++)
{
if(i==0||v[i]!=v[i-1])
if(v[i]!='0')ans++;
}
//cout<<a<<" "<<b<<" "<<c<<" -> "<<ans<<endl;
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,i,j;
cin>>n;
string s;
cin>>s;
q.push({-0,"0000"});
int ANS = 0;
while(!q.empty())
{
int k = -q.top().first;
string p = q.top().second;
q.pop();
int ans = mp[{k,p}];
auto it = mp.find({k,p}); mp.erase(it);
//cout<<k<<" "<<p<<" "<<ans<<endl;
char ch = s[k];if(k>=s.size())break;
int ans1 = ans+query(p[0],p[1],ch);
ANS = max(ANS,ans1);
string l = "";
l+=p[1];
l+=ch;
l+=p[2];
l+=p[3];
// cout<<l<<endl;
if(mp.count({k+1,l})==0)
{
mp[{k+1,l}] = ans1;
q.push({-k-1,l});
}
else
mp[{k+1,l}] = max(mp[{k+1,l}],ans1);
ans1 = ans+query(p[2],p[3],ch);
ANS = max(ANS,ans1);
l = "";
l+=p[0];
l+=p[1];
l+=p[3];
l+=ch;
// l="";
//l += p[0]+p[1]+p[3]+ch;
if(mp.count({k+1,l})==0)
{
mp[{k+1,l}] = ans1;
q.push({-k-1,l});
}
else
mp[{k+1,l}] = max(mp[{k+1,l}],ans1);
}
cout<<ANS<<endl;
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
