46772023-03-31 08:04:09TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 36/75583ms33548 KiB
using System;

namespace Valtakozz
{
    using System;
    using System.Linq;

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

            int[] cnt = new int[26];
            Array.Fill(cnt, 0);

            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)
                    {
                        if (2 * mx <= n || mx == cnt[i])
                        {
                            Console.Write(last = (char)(i + 'a'));
                            cnt[i]--;
                            break;
                        }
                    }
                }

                n--;
            }

            Console.WriteLine();
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base36/75
1Accepted0/027ms20952 KiB
2Accepted0/028ms21248 KiB
3Accepted3/327ms21864 KiB
4Accepted3/328ms22088 KiB
5Accepted3/327ms22584 KiB
6Accepted3/327ms22460 KiB
7Accepted3/375ms24208 KiB
8Time limit exceeded0/3504ms32260 KiB
9Accepted3/329ms24168 KiB
10Accepted3/329ms24320 KiB
11Accepted3/332ms23584 KiB
12Accepted3/332ms23708 KiB
13Accepted3/332ms23740 KiB
14Accepted3/332ms23668 KiB
15Time limit exceeded0/3564ms11928 KiB
16Time limit exceeded0/3569ms11932 KiB
17Time limit exceeded0/3523ms32720 KiB
18Time limit exceeded0/3521ms32788 KiB
19Accepted3/3488ms33148 KiB
20Time limit exceeded0/3540ms33476 KiB
21Time limit exceeded0/3563ms12404 KiB
22Time limit exceeded0/6542ms33548 KiB
23Time limit exceeded0/6583ms13280 KiB
24Time limit exceeded0/6555ms13396 KiB