# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580790 | HeyYouNotYouYou | Igra (COCI17_igra) | C++14 | 1 ms | 340 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 int long long
#define endl '\n'
using namespace std;
const int N = 30,INF=1e12;
string a,b;
int n;
int32_t main()
{
//freopen("abc.in", "r", stdin);
cin>>n;
cin>>a>>b;
int aa=0,bb=0,cc=0;
string ans="";
for(int i = 0 ; i < a.size() ; i++)
{
if(a[i]=='a') aa++;
else if(a[i]=='b') bb++;
else cc++;
}
vector<int>neara,nearb;
for(int i = 0 ; i < n ; i ++){
if(b[i]=='a' && bb)
ans+='b',bb--,nearb.push_back(i);
else if(b[i]=='a' && cc)
ans+='c',cc--;
else if(b[i]=='b' && aa)
ans+='a',aa--,neara.push_back(i);
else if(b[i]=='b' && cc)
ans+='c',cc--;
else if(b[i]=='c' && aa)
ans+='a',aa--;
else if(b[i]=='c' && bb)
ans+='b',bb--;
else if(b[i]=='c')
{
int you=-1,you1=-1;
if(nearb.size()) you=nearb.back();
if(neara.size()) you1=neara.back();
if(you>you1){
ans+='b';
ans[you]='c',cc--;
auto it=nearb.end();
it--;
nearb.erase(it);
}
else{
ans+='a';
ans[you1]='c',cc--;
auto it=neara.end();
it--;
neara.erase(it);
}
}
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |