Submission #371245

# Submission time Handle Problem Language Result Execution time Memory
371245 2021-02-26T09:36:50 Z FatihSolak Igra (COCI17_igra) C++17
100 / 100
1 ms 492 KB
#include <bits/stdc++.h>
#define N 5005
using namespace std;
int cnt[3];
int suf[N][3];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<3;j++){
			suf[i][j] = suf[i+1][j] + ((t[i]-'a') == j);
		}
		cnt[s[i]-'a']++;
	}
	string ans;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			bool ok = 1;
			for(int c=0;c<3;c++){
				int sum = 0;
				for(int d=0;d<3;d++){
					if(d != c)sum+=cnt[d] - (d == j);
				}
				if(suf[i+1][c] > sum){
					ok = 0;
				}
			}
			if(cnt[j] && (t[i]-'a') != j && ok){
				ans+='a'+j;
				cnt[j]--;
				break;
			}
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct