47412023-03-31 10:35:48TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 33/75592ms70352 KiB
using System;
using System.Linq;
namespace Valtakozz
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine().Trim();
            string output = "";
            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;
            }
            while (n >= 1)
            {
                for (int i = 0; i < 26; i++)
                {
                    if (last != (char)(i + 'a') && cnt[i] > 0 && (2 * mx <= n || mx == cnt[i]))
                    {
                        last = (char)(i + 'a');
                        output += last;
                        cnt[i]--;
                        break;
                    }
                }
                n--;
                mx = cnt.Max();
            }
            Console.WriteLine(output);
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base33/75
1Accepted0/027ms20628 KiB
2Accepted0/028ms23644 KiB
3Accepted3/328ms21728 KiB
4Accepted3/328ms22304 KiB
5Accepted3/327ms21824 KiB
6Accepted3/326ms22380 KiB
7Accepted3/3356ms70352 KiB
8Time limit exceeded0/3592ms30464 KiB
9Accepted3/328ms24288 KiB
10Accepted3/328ms24164 KiB
11Accepted3/332ms31652 KiB
12Accepted3/332ms31724 KiB
13Accepted3/332ms31784 KiB
14Accepted3/334ms31724 KiB
15Time limit exceeded0/3589ms31332 KiB
16Time limit exceeded0/3568ms31292 KiB
17Time limit exceeded0/3565ms31684 KiB
18Time limit exceeded0/3583ms31872 KiB
19Time limit exceeded0/3566ms31824 KiB
20Time limit exceeded0/3574ms31672 KiB
21Time limit exceeded0/3578ms32284 KiB
22Time limit exceeded0/6575ms32596 KiB
23Time limit exceeded0/6542ms32648 KiB
24Time limit exceeded0/6560ms32680 KiB