# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
66374 |
2018-08-10T10:42:12 Z |
KLPP |
Igra (COCI17_igra) |
C++14 |
|
67 ms |
712 KB |
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdio.h>
using namespace std;
string s,m;
int n;
bool check(int pos,int a, int b, int c){
if(a<0 || b<0 || c<0)return false;
int A=a;
int B=b;
int C=c;
for(int i=pos;i<n;i++){
if(m.at(i)=='a')A++;
if(m.at(i)=='b')B++;
if(m.at(i)=='c')C++;
}
if(A>n-pos || B>n-pos || C>n-pos)return false;
return true;
}
int main(){
cin>>n;
cin>>s;
cin>>m;
int a,b,c;
a=0;
b=0;
c=0;
for(int i=0;i<n;i++){
if(s.at(i)=='a')a++;
if(s.at(i)=='b')b++;
if(s.at(i)=='c')c++;
}
string ans;
for(int i=0;i<n;i++){
if(m.at(i)=='a'){
if(check(i+1,a,b-1,c)){
b--;
ans+='b';
}else{
c--;
ans+='c';
}
}
if(m.at(i)=='b'){
if(check(i+1,a-1,b,c)){
a--;
ans+='a';
}else{
c--;
ans+='c';
}
}
if(m.at(i)=='c'){
if(check(i+1,a-1,b,c)){
a--;
ans+='a';
}else{
b--;
ans+='b';
}
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
67 ms |
620 KB |
Output is correct |
10 |
Correct |
66 ms |
712 KB |
Output is correct |