2482021-03-05 16:24:02Valaki2Váltakozó (75 pont)cpp14Accepted 75/7528ms4984 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	string s;
  char b;
  int a=0;
  cin >> s;
  vector<int> x(26, 0);
  for (int i=0; i<s.size(); i++) {
    x[s[i]-'a']++;
    if (x[s[i]-'a']>(s.size()+s.size()%2)/2) a=1;
  }
  b='A';
  if (a) cout << "-1" << endl;
  else {
    for (int i=0; i<s.size(); i++) {
      a=-1;
      for (int j=0; j<26; j++) {
        if (char(j+'a')!=b && x[j]>0) {
          if (a==-1) a=j;
          else if ((s.size()-i)/2<x[j]) a=j;
        }
      }
      b=char(a+'a');
      x[a]--;
      cout << b;
    }
  }
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/02ms1740 KiB
2Accepted0/01ms1768 KiB
3Accepted3/31ms1828 KiB
4Accepted3/31ms1832 KiB
5Accepted3/31ms1840 KiB
6Accepted3/31ms1844 KiB
7Accepted3/33ms1908 KiB
8Accepted3/328ms2736 KiB
9Accepted3/36ms2940 KiB
10Accepted3/37ms3136 KiB
11Accepted3/31ms2472 KiB
12Accepted3/32ms2476 KiB
13Accepted3/31ms2480 KiB
14Accepted3/31ms2480 KiB
15Accepted3/319ms3348 KiB
16Accepted3/317ms3436 KiB
17Accepted3/317ms3756 KiB
18Accepted3/319ms3828 KiB
19Accepted3/317ms4024 KiB
20Accepted3/317ms4332 KiB
21Accepted3/318ms4396 KiB
22Accepted6/618ms4628 KiB
23Accepted6/619ms4808 KiB
24Accepted6/617ms4984 KiB