Submission #1359479

#TimeUsernameProblemLanguageResultExecution timeMemory
1359479AOrdinaryIgra (COCI17_igra)C++20
100 / 100
0 ms344 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long 
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define sz(s) s.size()
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 1e6 + 9 , mod = 1e9 + 7;
const ll inf = 1e18;
const ll MOD = (ll)1e9+7;
 
void solve() {	
	ll n; cin >> n;
	string res = "";
	string a,b; cin >> a >> b;
	map<char, ll> mp1;
	map<char, ll> mp2;
	for(ll i = 0;i<n;i++){
		mp1[a[i]]++;
		mp2[b[i]]++;
	} //sort(all(a));
	
	ll cnt = n;
	for(ll i = 0;i<n;i++){
		mp2[b[i]]--; 
    for(char ch : {'a', 'b', 'c'}) {
			
			if(mp1[ch] > 0 && ch != b[i]) {
				
				mp1[ch]--;
				
				bool safe = true;
				for(char k : {'a', 'b', 'c'}) {
					if(mp1[k] + mp2[k] > cnt - 1) {
						safe = false;
					}
				}
				
				if(safe) {
					res += ch;
					break; 
				} else {
					mp1[ch]++;
				}
			}
		}
		
		cnt--;
	} cout << res << endl;
	
}
int32_t main(){
    //freopen("kgraph.in", "r", stdin);
    //freopen("kgraph.out", "w", stdout);
    TL;
    int test = 1; //cin>>test;
    while(test--)	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...