# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152766 | sofhiasouza | Igra (COCI17_igra) | C++14 | 4 ms | 504 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, A, B, C;
string a, b, resp;
priority_queue < int > v1, v3, v5;
int main()
{
cin >> n;
cin >> a >> b;
char resp[maxn];
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
{
resp[i] = 'c';
c3--;
}
}
else if(b[i] == 'b')
{
if(c1)
{
resp[i] = 'a';
c1--;
v3.push(i);
}
else if(c3)
{
resp[i] = 'c';
c3--;
}
else
{
int u5 = v5.top();
v5.pop();
resp[u5] = 'b';
c2--;
resp[i] = 'a';
v3.push(i);
}
}
else
{
if(c1)
{
resp[i] = 'a';
c1--;
v5.push(i);
}
else if(c2)
{
resp[i] = 'b';
c2--;
}
else
{
resp[i] = '?';
C++;
}
}
}
while(C)
{
int u1 = -1, u3 = -1;
if(v1.size()) u1 = v1.top();
if(v3.size()) u3 = v3.size();
if(u1 > u3)
{
B++;
v1.pop();
resp[u1] = 'c';
}
else
{
A++;
v3.pop();
resp[u3] = 'c';
}
C--;
}
for(int i = 0 ; i < n ; i++)
{
if(resp[i] != '?') cout << resp[i];
else
{
if(A)
{
cout << 'a';
A--;
}
else cout << 'b';
}
}
cout << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |