Submission #163457

# Submission time Handle Problem Language Result Execution time Memory
163457 2019-11-13T12:00:42 Z quoriess Igra (COCI17_igra) C++14
100 / 100
3 ms 380 KB
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;
#define dbg(x) cout << #x << " has a value of: " << x << "\n";
#define usize(x) (int)(x.size())
#define plist(x)                       \
    for (int i = 0; i < usize(x); i++) \
        cout << "eleman " << i << " = " << x[i] << "\n";
#define foreach(x) for (auto item : x)
#define fill(s, x)              \
    for (int i = 0; i < x; i++) \
        cin >> s[i];
#define in(veriler, a) (veriler.find(a) != veriler.end())
#define btw(x, y, z) x >= y&& x <= z;
std::ostream& operator<<(std::ostream& os, pair<int,int> p) {
    os << p.first << ", " << p.second;
    return os;
}
#ifdef ONLINE_JUDGE
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#else
#define fio //a
#endif
int main(){
	int n;
	cin>>n;
	string ltrs,frb;
	cin>>ltrs>>frb;
	string res="";
	vector<int> freq(3);
	
	vector<int> frbq(3);
	for(int i=0;i<n;i++){
		freq[ltrs[i]-'a']++;
		frbq[frb[i]-'a']++;
	}
	for(int i=0;i<n;i++){
		frbq[frb[i]-'a']--;
		for(int j=0;j<3;j++){
			if(freq[j]==0)continue;
			if(j==frb[i]-'a'){
				continue;
			}
			freq[j]--;
			bool h=true;
			for(int k=0;k<3;k++){
				if(freq[k]+frbq[k]>n-i-1){h=false;}
			}
			if(h){
				res+=j+'a';
				break;
			}
			else{
				freq[j]++;
			}
		}
	}
	cout<<res<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct