2202021-03-04 23:24:44mraronVáltakozó (75 pont)cpp14Accepted 75/7535ms5112 KiB
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	
	array<int, 26> cnt;
	fill(cnt.begin(), cnt.end(), 0);
	
	for(char c:s) cnt[c-'a']++;
	
	int n=s.size(), mx=*max_element(cnt.begin(), cnt.end());
	char last='-';
	
	if(2*mx>n+1) {
		cout<<"-1";
		return 0;
	}
	
	while(n>=1) {
		mx=*max_element(cnt.begin(), cnt.end());
		for(int i=0;i<26;++i) {
			if(last!=i+'a' && cnt[i]) {
				if(2*mx<=n || mx==cnt[i]) {
					cout<<(last=i+'a');
					cnt[i]--;
					break ;
				}
			}
		}
		
		n--;
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/02ms1736 KiB
2Accepted0/01ms1840 KiB
3Accepted3/32ms1832 KiB
4Accepted3/31ms1836 KiB
5Accepted3/31ms1848 KiB
6Accepted3/31ms1844 KiB
7Accepted3/34ms1896 KiB
8Accepted3/335ms2736 KiB
9Accepted3/37ms2816 KiB
10Accepted3/37ms3120 KiB
11Accepted3/31ms2476 KiB
12Accepted3/32ms2480 KiB
13Accepted3/31ms2476 KiB
14Accepted3/31ms2480 KiB
15Accepted3/320ms3232 KiB
16Accepted3/324ms3544 KiB
17Accepted3/323ms3632 KiB
18Accepted3/323ms3828 KiB
19Accepted3/320ms4136 KiB
20Accepted3/323ms4332 KiB
21Accepted3/324ms4528 KiB
22Accepted6/619ms4720 KiB
23Accepted6/632ms4804 KiB
24Accepted6/635ms5112 KiB