# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
490332 |
2021-11-27T07:11:35 Z |
niloyroot |
Igra (COCI17_igra) |
C++14 |
|
34 ms |
216 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1000000007;
void solve(){
ll n; cin>>n;
string a,b; cin>>a>>b;
sort(a.begin(), a.end());
char c; ll ind;
forp(i,0,n-1){
if(a[i]==b[i]){
c='z'; ind=-1;
forp(j,i+1,n-1){
if(a[j]!=a[i] && b[j]!=a[i]){
if(c=='z'){
c=a[j];
ind=j;
} else if(a[j]<c){
ind=j; break;
}
}
}
if(ind==-1){
forn(j,i-1,0){
if(a[j]!=a[i] && b[j]!=a[i]){
ind=j; break;
}
}
}
swap(a[i],a[ind]);
}
}
forp(i,0,n-1){
forp(j,0,i-1){
if(b[i]==b[j]&&a[j]>a[i]){
swap(a[i],a[j]); break;
}
}
}
cout<<a<<newl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1; //cin>>t;
while(t--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
216 KB |
Output is correct |
6 |
Correct |
0 ms |
216 KB |
Output is correct |
7 |
Correct |
1 ms |
216 KB |
Output is correct |
8 |
Correct |
1 ms |
216 KB |
Output is correct |
9 |
Correct |
33 ms |
216 KB |
Output is correct |
10 |
Correct |
34 ms |
216 KB |
Output is correct |