78252024-01-11 12:17:55AblablablaVáltakozó (75 pont)cpp17Wrong answer 14/7527ms4940 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']++;
    }

    for(int i = 0; i < 26; i++){
        if(betuk[i] > n / 2 + (n % 2)){
            cout << "-1\n";
            return 0;
        }
    }

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

    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base14/75
1Wrong answer0/03ms2092 KiB
2Wrong answer0/03ms2316 KiB
3Partially correct2/33ms2340 KiB
4Partially correct2/33ms2580 KiB
5Partially correct2/33ms2552 KiB
6Wrong answer0/33ms2684 KiB
7Wrong answer0/34ms2952 KiB
8Wrong answer0/318ms3820 KiB
9Accepted3/38ms3904 KiB
10Accepted3/38ms3924 KiB
11Wrong answer0/33ms3240 KiB
12Wrong answer0/33ms3380 KiB
13Wrong answer0/33ms3468 KiB
14Wrong answer0/33ms3476 KiB
15Partially correct2/327ms4312 KiB
16Wrong answer0/325ms4532 KiB
17Wrong answer0/325ms4608 KiB
18Wrong answer0/326ms4664 KiB
19Wrong answer0/325ms4676 KiB
20Wrong answer0/325ms4784 KiB
21Wrong answer0/325ms4864 KiB
22Wrong answer0/626ms4800 KiB
23Wrong answer0/625ms4772 KiB
24Wrong answer0/621ms4940 KiB