92272024-02-19 06:48:41xxxVáltakozó (75 pont)cpp17Wrong answer 69/7523ms4744 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
    string s;
    cin >> s;
    int n = s.length();
    int nc = n;

    int chars[26] = {0};

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

    for(int i = 0; i < 26; i++) {
        if (chars[i] > n/2) {
            cout << -1 << endl;
            return 0;
        }
    }
    int jochar = -1, elozo = -2;

    for(int i = 0; i < n; i++) {
        for(int j = 25; j >= 0; j--) {
            if (chars[j] <= 0 || elozo == j) {
                continue;
            }
            if (nc%2 == 1 && chars[j] > nc/2) {
                jochar = j;
                j = -10;
            } else {
                jochar = j;
            }
        }
        
        
        cout << (char)(jochar+'a');
        //cout << nc << ' ';
        nc--;
        chars[jochar]--;
        elozo = jochar;
    }

    return 0;    
}
SubtaskSumTestVerdictTimeMemory
base69/75
1Accepted0/03ms1812 KiB
2Accepted0/03ms2056 KiB
3Accepted3/33ms2268 KiB
4Accepted3/33ms2480 KiB
5Accepted3/33ms2928 KiB
6Accepted3/33ms2888 KiB
7Wrong answer0/33ms3308 KiB
8Wrong answer0/37ms3776 KiB
9Accepted3/37ms4036 KiB
10Accepted3/37ms4088 KiB
11Accepted3/33ms3404 KiB
12Accepted3/33ms3508 KiB
13Accepted3/33ms3652 KiB
14Accepted3/33ms3728 KiB
15Accepted3/323ms4316 KiB
16Accepted3/323ms4320 KiB
17Accepted3/320ms4276 KiB
18Accepted3/320ms4584 KiB
19Accepted3/323ms4744 KiB
20Accepted3/323ms4700 KiB
21Accepted3/321ms4696 KiB
22Accepted6/623ms4700 KiB
23Accepted6/623ms4696 KiB
24Accepted6/619ms4696 KiB