2622021-03-07 17:19:34Valaki2Váltakozó (75 pont)cpp14Accepted 75/7521ms5000 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	string s;
  cin >> s;
  vector<int> v(26, 0);
  for(int i = 0; i < s.size(); ++i) {
    ++v[s[i]-'a'];
  }
  for(int i = 0; i < 26; ++i) {
    if(s.size()%2==1) {
      if(v[i] > s.size()/2+1) {
        cout << "-1\n";
        return 0;
      }
    }
    if(s.size()%2==0) {
      if(v[i] > s.size()/2) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  int l = -1;
  for(int i = 0; i < s.size(); ++i) {
    int ind = -1;
    for(int j = 25; j >= 0; --j) {
      if(!v[j]) continue;
      if(j==l) continue;
      if((s.size()-i)%2==1 && v[j] == (s.size()-i)/2+1) {
        ind = j;
        break;
      }
      ind = j;
    }
    cout << (char) (ind + 'a');
    --v[ind];
    l = ind;
  }
  cout << "\n";
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/02ms1736 KiB
2Accepted0/02ms1776 KiB
3Accepted3/31ms1840 KiB
4Accepted3/31ms1848 KiB
5Accepted3/31ms1848 KiB
6Accepted3/31ms1852 KiB
7Accepted3/32ms1908 KiB
8Accepted3/316ms2636 KiB
9Accepted3/37ms2952 KiB
10Accepted3/36ms3020 KiB
11Accepted3/31ms2480 KiB
12Accepted3/31ms2480 KiB
13Accepted3/31ms2488 KiB
14Accepted3/31ms2492 KiB
15Accepted3/317ms3360 KiB
16Accepted3/321ms3444 KiB
17Accepted3/318ms3620 KiB
18Accepted3/317ms3816 KiB
19Accepted3/321ms4036 KiB
20Accepted3/318ms4340 KiB
21Accepted3/319ms4532 KiB
22Accepted6/618ms4728 KiB
23Accepted6/618ms4924 KiB
24Accepted6/617ms5000 KiB