92282024-02-19 06:50:29xxxVáltakozó (75 pont)cpp17Wrong answer 69/7523ms3976 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;
    }
	cout << endl;

    return 0;    
}
SubtaskSumTestVerdictTimeMemory
base69/75
1Accepted0/03ms1956 KiB
2Accepted0/03ms2116 KiB
3Accepted3/33ms2332 KiB
4Accepted3/33ms2440 KiB
5Accepted3/32ms2484 KiB
6Accepted3/32ms2488 KiB
7Wrong answer0/33ms2536 KiB
8Wrong answer0/37ms3340 KiB
9Accepted3/37ms3548 KiB
10Accepted3/38ms3764 KiB
11Accepted3/33ms3228 KiB
12Accepted3/33ms3136 KiB
13Accepted3/33ms3136 KiB
14Accepted3/33ms3240 KiB
15Accepted3/320ms3716 KiB
16Accepted3/323ms3716 KiB
17Accepted3/320ms3712 KiB
18Accepted3/319ms3976 KiB
19Accepted3/321ms3932 KiB
20Accepted3/321ms3928 KiB
21Accepted3/321ms3932 KiB
22Accepted6/621ms3928 KiB
23Accepted6/621ms3932 KiB
24Accepted6/619ms3932 KiB