47152023-03-31 09:52:51TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 36/75570ms34636 KiB
using System;
using System.Linq;
namespace Valtakozz
{

    class Program
    {
        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;
            }

            while (n >= 1)
            {
                mx = cnt.Max();
                for (int i = 0; i < 26; i++)
                {
                    if (last != (char)(i + 'a') && cnt[i] > 0 && (2 * mx <= n || mx == cnt[i]))
                    {
                        Console.Write(last = (char)(i + 'a'));
                        cnt[i]--;
                        break;
                    }
                }

                n--;
            }

            Console.WriteLine();
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base36/75
1Accepted0/028ms21020 KiB
2Accepted0/029ms21428 KiB
3Accepted3/328ms21604 KiB
4Accepted3/327ms22156 KiB
5Accepted3/327ms22056 KiB
6Accepted3/328ms22680 KiB
7Accepted3/382ms23724 KiB
8Time limit exceeded0/3544ms31648 KiB
9Accepted3/330ms23912 KiB
10Accepted3/328ms24008 KiB
11Accepted3/332ms23216 KiB
12Accepted3/332ms23840 KiB
13Accepted3/332ms24040 KiB
14Accepted3/332ms24188 KiB
15Accepted3/3497ms33484 KiB
16Time limit exceeded0/3507ms33476 KiB
17Time limit exceeded0/3513ms33460 KiB
18Time limit exceeded0/3514ms33488 KiB
19Time limit exceeded0/3504ms33848 KiB
20Time limit exceeded0/3566ms13180 KiB
21Time limit exceeded0/3570ms13528 KiB
22Time limit exceeded0/6500ms34236 KiB
23Time limit exceeded0/6555ms13732 KiB
24Time limit exceeded0/6523ms34636 KiB