Submission #490332

#TimeUsernameProblemLanguageResultExecution timeMemory
490332niloyrootIgra (COCI17_igra)C++14
100 / 100
34 ms216 KiB
#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 timeMemoryGrader output
Fetching results...