92382024-02-19 10:52:33xxxVáltakozó (75 pont)cpp17Wrong answer 69/7521ms4636 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+1) {
                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/03ms1812 KiB
2Accepted0/03ms2060 KiB
3Accepted3/33ms2272 KiB
4Accepted3/33ms2508 KiB
5Accepted3/32ms2628 KiB
6Accepted3/33ms2864 KiB
7Wrong answer0/33ms3088 KiB
8Wrong answer0/37ms3584 KiB
9Accepted3/37ms3840 KiB
10Accepted3/37ms4024 KiB
11Accepted3/33ms3524 KiB
12Accepted3/33ms3608 KiB
13Accepted3/33ms3580 KiB
14Accepted3/33ms3688 KiB
15Accepted3/320ms4272 KiB
16Accepted3/320ms4432 KiB
17Accepted3/319ms4220 KiB
18Accepted3/319ms4172 KiB
19Accepted3/321ms4172 KiB
20Accepted3/321ms4484 KiB
21Accepted3/320ms4380 KiB
22Accepted6/621ms4636 KiB
23Accepted6/620ms4596 KiB
24Accepted6/618ms4596 KiB