78362024-01-11 12:38:38AblablablaVáltakozó (75 pont)cpp17Accepted 75/7526ms4460 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;

    int n = s.size();

    vector<int> betuk(26, 0);
    vector<pii> sorrend;

    for(int i = 0; i < n; i++){
        betuk[s[i] - 'a']++;
    }

    int maxi = *max_element(betuk.begin(), betuk.end());
    if(maxi > n / 2 + n % 2){
        cout << "-1\n";
        return 0;
    }

    int utolso = -1;
    for(int i = 0; i < n; i++){
        maxi = *max_element(betuk.begin(), betuk.end());
        for(int j = 0; j < 26; j++){
            if(utolso != j && betuk[j]){
                if(2 * maxi <= n - i || maxi == betuk[j]){
                    cout << (char)(j + 'a');
                    utolso = j;
                    betuk[j]--;
                    break;
                }
            }
        }
    }

    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1956 KiB
2Accepted0/03ms2116 KiB
3Accepted3/33ms2224 KiB
4Accepted3/32ms2268 KiB
5Accepted3/33ms2396 KiB
6Accepted3/33ms2636 KiB
7Accepted3/34ms3048 KiB
8Accepted3/324ms3528 KiB
9Accepted3/38ms3712 KiB
10Accepted3/38ms3888 KiB
11Accepted3/33ms3204 KiB
12Accepted3/33ms3480 KiB
13Accepted3/33ms3536 KiB
14Accepted3/33ms3568 KiB
15Accepted3/324ms4244 KiB
16Accepted3/324ms4144 KiB
17Accepted3/325ms4200 KiB
18Accepted3/325ms4460 KiB
19Accepted3/323ms4344 KiB
20Accepted3/323ms4344 KiB
21Accepted3/324ms4344 KiB
22Accepted6/621ms4348 KiB
23Accepted6/623ms4348 KiB
24Accepted6/626ms4396 KiB