# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155159 | phillip | Igra (COCI17_igra) | C++14 | 3 ms | 376 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;
int dp[5009][3];
int n,a[5009];
int x[5009];
string s;
int main()
{
cin>>n>>s;
for(int i=0;i<n;i++)x[s[i]-'a']++;
cin>>s;
for(int i=n-1;i>=0;i--)
{
for(int j=0;j<3;j++)dp[i][j]=dp[i-1][j];
dp[i][s[i]-'a']++;
}
for(int i=0;i<n;i++)
{
int num=s[i]-'a';
if(i==n-1)
{
for(int j=0;j<3;j++)
{
if(x[j])a[i]=j;
}
break;
}
for(int j=0;j<3;j++)
{
if(j==num)continue;
if(x[j]==0)continue;
int k;
if(num==0)
{
if(j==1)k=2;
else k=1;
}
if(num==1)
{
if(j==2)k=0;
else k=2;
}
if(num==2)
{
if(j==1)k=0;
else k=1;
}
if(x[num]+x[j]>dp[i+1][k])
{
x[j]--;
a[i]=j;
break;
}
}
//for(int i=0;i<3;i++)cout<<x[i]<<" ";cout<<"\n";
}
for(int i=0;i<n;i++)cout<<char('a'+a[i]);
}
/*
6
abcaaa
aabbbb
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |