# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
152417 |
2019-09-07T23:22:26 Z |
sofhiasouza |
Igra (COCI17_igra) |
C++14 |
|
3 ms |
376 KB |
#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
igra.cpp: In function 'int main()':
igra.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < a.size() ; i++)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 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 |
376 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 |
376 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |