#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 > u[7];
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--;
u[1].push(i);
}
else if(c3)
{
resp[i] = 'c';
c3--;
u[2].push(i);
}
else
{
int u4 = u[4].top(), u6 = u[6].top();
if(u4 < u6)
{
u[4].pop();
resp[u4] = 'a';
c1--;
resp[i] = 'c';
u[3].push(u4);
u[2].push(i);
}
else
{
u[6].pop();
resp[u6] = 'a';
c1--;
resp[i] = 'b';
u[5].push(u6);
u[1].push(i);
}
}
}
else if(b[i] == 'b')
{
if(c1)
{
resp[i] = 'a';
c1--;
u[3].push(i);
}
else if(c3)
{
resp[i] = 'c';
c3--;
u[4].push(i);
}
else
{
int u2 = u[2].top(), u5 = u[5].top();
if(u2 < u5)
{
u[2].pop();
resp[u2] = 'b';
c2--;
resp[i] = 'c';
u[1].push(u2);
u[4].push(i);
}
else
{
u[5].pop();
resp[u5] = 'b';
c2--;
resp[i] = 'a';
u[6].push(u5);
u[3].push(i);
}
}
}
else
{
if(c1)
{
resp[i] = 'a';
c1--;
u[5].push(i);
}
else if(c2)
{
resp[i] = 'b';
c2--;
u[6].push(i);
}
else
{
int u1 = u[1].top(), u3 = u[3].top();
if(u1 > u3)
{
u[1].pop();
resp[u1] = 'c';
c3--;
resp[i] = 'b';
u[2].push(u1);
u[6].push(i);
}
else
{
u[3].pop();
resp[u3] = 'c';
c3--;
resp[i] = 'a';
u[4].push(u3);
u[5].push(i);
}
}
}
}
cout << resp << "\n";
}
Compilation message
igra.cpp: In function 'int main()':
igra.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < a.size() ; i++)
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
380 KB |
Output isn't correct |