47122023-03-31 09:51:28TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 54/75550ms34388 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)
                    {
                        if (2 * mx <= n || mx == cnt[i])
                        {
                            Console.Write(last = (char)(i + 'a'));
                            cnt[i]--;
                            break;
                        }
                    }
                }

                n--;
            }

            Console.WriteLine();
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base54/75
1Accepted0/028ms20952 KiB
2Accepted0/030ms21352 KiB
3Accepted3/327ms21484 KiB
4Accepted3/327ms21652 KiB
5Accepted3/327ms21968 KiB
6Accepted3/327ms22404 KiB
7Accepted3/375ms24012 KiB
8Time limit exceeded0/3532ms32232 KiB
9Accepted3/329ms23716 KiB
10Accepted3/329ms23828 KiB
11Accepted3/332ms23452 KiB
12Accepted3/332ms23964 KiB
13Accepted3/332ms24180 KiB
14Accepted3/330ms24796 KiB
15Accepted3/3493ms33676 KiB
16Time limit exceeded0/3550ms12796 KiB
17Accepted3/3500ms34060 KiB
18Time limit exceeded0/3504ms33956 KiB
19Accepted3/3479ms34024 KiB
20Time limit exceeded0/3528ms33772 KiB
21Time limit exceeded0/3547ms13408 KiB
22Accepted6/6486ms34388 KiB
23Accepted6/6500ms34188 KiB
24Time limit exceeded0/6504ms33888 KiB