# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
639676 | ningia203 | Igra (COCI17_igra) | C++14 | 1 ms | 340 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>
using namespace std;
long n,cnt1,cnt2,cnt3;
string s,t;
vector<long> ds1;
vector<long> ds2;
vector<long> ds3;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>n;
cin>>s>>t;
sort(s.begin(),s.end());
for(long i=0; i<n; i++){
if(s[i]==t[i]){
if(s[i]=='a') ds1.push_back(i);
else if(s[i]=='b') ds2.push_back(i);
else ds3.push_back(i);
}
}
cnt1=0;
cnt2=0;
cnt3=0;
while(cnt1<ds1.size()){
if(cnt2<ds2.size()){
s[ds1[cnt1]]='b';
s[ds2[cnt2]]='a';
cnt1++;
cnt2++;
}
else{
s[ds1[cnt1]]='c';
s[ds3[cnt3]]='a';
cnt1++;
cnt3++;
}
}
while(cnt2<ds2.size()){
s[ds2[cnt2]]='c';
s[ds3[cnt3]]='b';
cnt2++;
cnt3++;
}
while(cnt3<ds3.size()){
if(cnt2>0){
cnt2--;
swap(s[ds3[cnt3]],s[ds2[cnt2]]);
}
else{
cnt1--;
swap(s[ds3[cnt3]],s[ds1[cnt1]]);
}
cnt3++;
}
cout<<s;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |