46782023-03-31 08:07:58TortelliniJrVáltakozó (75 pont)csharpWrong answer 27/75587ms31248 KiB
using System;
using System.Linq;

class MainClass
{
    public static void Main(string[] args)
    {
        string s = Console.ReadLine();

        int[] cnt = new int[26];

        foreach (char c in s)
        {
            cnt[c - 'a']++;
        }

        int n = s.Length, mx = cnt.Max();
        char last = '-';

        if (2 * mx > n + 1)
        {
            Console.WriteLine("-1");
            return;
        }

        for (int i = 0; i < n; i++)
        {
            mx = cnt.Max();
            int secondMx = cnt.OrderByDescending(x => x).Skip(1).First();
            for (int j = 0; j < 26; j++)
            {
                if (last != (char)('a' + j) && cnt[j] > 0)
                {
                    if (mx == cnt[j] || mx <= (n - i - 1) / 2 && secondMx <= n - i - mx - 2)
                    {
                        Console.Write((char)('a' + j));
                        cnt[j]--;
                        last = (char)('a' + j);
                        break;
                    }
                }
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base27/75
1Wrong answer0/032ms21308 KiB
2Wrong answer0/039ms23092 KiB
3Partially correct2/332ms22024 KiB
4Accepted3/332ms22108 KiB
5Partially correct2/332ms22748 KiB
6Accepted3/332ms22864 KiB
7Accepted3/3136ms31248 KiB
8Time limit exceeded0/3560ms11840 KiB
9Accepted3/330ms24096 KiB
10Accepted3/329ms24024 KiB
11Partially correct2/346ms25864 KiB
12Partially correct2/345ms25888 KiB
13Partially correct2/345ms25888 KiB
14Partially correct2/343ms25564 KiB
15Time limit exceeded0/3558ms12056 KiB
16Time limit exceeded0/3566ms12616 KiB
17Time limit exceeded0/3550ms12532 KiB
18Time limit exceeded0/3575ms12836 KiB
19Time limit exceeded0/3552ms12792 KiB
20Time limit exceeded0/3575ms12840 KiB
21Time limit exceeded0/3587ms13120 KiB
22Time limit exceeded0/6568ms13188 KiB
23Time limit exceeded0/6555ms13488 KiB
24Time limit exceeded0/6555ms13628 KiB