47102023-03-31 09:50:37TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 33/75578ms33448 KiB
using System;

namespace Valtakozz
{
    using System;
    using System.Linq;

    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
base33/75
1Accepted0/028ms20392 KiB
2Accepted0/028ms21220 KiB
3Accepted3/328ms21468 KiB
4Accepted3/327ms21732 KiB
5Accepted3/328ms22116 KiB
6Accepted3/327ms22456 KiB
7Accepted3/393ms23776 KiB
8Time limit exceeded0/3563ms32412 KiB
9Accepted3/330ms23980 KiB
10Accepted3/329ms24156 KiB
11Accepted3/332ms23636 KiB
12Accepted3/332ms23684 KiB
13Accepted3/332ms23648 KiB
14Accepted3/332ms23824 KiB
15Time limit exceeded0/3519ms33044 KiB
16Time limit exceeded0/3578ms11936 KiB
17Time limit exceeded0/3554ms33224 KiB
18Time limit exceeded0/3527ms33172 KiB
19Time limit exceeded0/3509ms33056 KiB
20Time limit exceeded0/3560ms33244 KiB
21Time limit exceeded0/3568ms33420 KiB
22Time limit exceeded0/6555ms33448 KiB
23Time limit exceeded0/6566ms12744 KiB
24Time limit exceeded0/6517ms33328 KiB