92232024-02-18 19:12:11xxxVáltakozó (75 pont)cpp14Wrong answer 69/7523ms4556 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 (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/03ms1948 KiB
3Accepted3/33ms2164 KiB
4Accepted3/32ms2268 KiB
5Accepted3/33ms2404 KiB
6Accepted3/33ms2740 KiB
7Wrong answer0/33ms2756 KiB
8Wrong answer0/37ms3472 KiB
9Accepted3/37ms3544 KiB
10Accepted3/38ms3700 KiB
11Accepted3/33ms3168 KiB
12Accepted3/33ms3068 KiB
13Accepted3/33ms3208 KiB
14Accepted3/33ms3584 KiB
15Accepted3/321ms4000 KiB
16Accepted3/323ms4016 KiB
17Accepted3/320ms4076 KiB
18Accepted3/320ms4048 KiB
19Accepted3/323ms4108 KiB
20Accepted3/323ms4224 KiB
21Accepted3/321ms4308 KiB
22Accepted6/623ms4468 KiB
23Accepted6/623ms4544 KiB
24Accepted6/620ms4556 KiB