# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152417 | sofhiasouza | 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 pb push_back
using namespace std;
const int maxn = 5e3+10;
int n, c1, c2, c3;
string a, b, resp;
priority_queue < int > v1, v3, v5;
priority_queue < int, vector < int >, greater < int > > v2, v4, v6;
int main()
{
cin >> n;
cin >> a >> b;
resp = b;
for(int i = 0 ; i < a.size() ; i++)
{
if(a[i] == 'a') c1++;
else if(a[i] == 'b') c2++;
else c3++;
}
for(int i = 0 ; i < n ; i++)
{
if(b[i] == 'a')
{
if(c2)
{
resp[i] = 'b';
c2--;
v1.push(i);
}
else if(c3)
{
resp[i] = 'c';
c3--;
v2.push(i);
}
else
{
int u4 = v4.top(), u6 = v6.top();
if(u4 < u6)
{
v4.pop();
resp[u4] = 'a';
c1--;
resp[i] = 'c';
v3.push(u4);
v2.push(i);
}
else
{
v6.pop();
resp[u6] = 'a';
c1--;
resp[i] = 'b';
v5.push(u6);
v1.push(i);
}
}
}
else if(b[i] == 'b')
{
if(c1)
{
resp[i] = 'a';
c1--;
v3.push(i);
}
else if(c3)
{
resp[i] = 'c';
c3--;
v4.push(i);
}
else
{
int u2 = v2.top(), u5 = v5.top();
if(u2 < u5)
{
v2.pop();
resp[u2] = 'b';
c2--;
resp[i] = 'c';
v1.push(u2);
v4.push(i);
}
else
{
v5.pop();
resp[u5] = 'b';
c2--;
resp[i] = 'a';
v6.push(u5);
v3.push(i);
}
}
}
else
{
if(c1)
{
resp[i] = 'a';
c1--;
v5.push(i);
}
else if(c2)
{
resp[i] = 'b';
c2--;
v6.push(i);
}
else
{
int u1 = v1.top(), u3 = v3.top();
if(u1 > u3)
{
v1.pop();
resp[u1] = 'c';
c3--;
resp[i] = 'b';
v2.push(u1);
v6.push(i);
}
else
{
v3.pop();
resp[u3] = 'c';
c3--;
resp[i] = 'a';
v4.push(u3);
v5.push(i);
}
}
}
}
cout << resp << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |