#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);
// cout << i << "\n";
}
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.top();
//cout << u1 << ' ' << u3 << "\n";
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
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 |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is 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 |
256 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |