47252023-03-31 10:03:55TortelliniJrVáltakozó (75 pont)csharpWrong answer 6/75173ms33564 KiB
using System;
using System.Linq;
namespace Valtakozz
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            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;
            }
            char current = '-';
            while (n >= 1)
            {
                mx = cnt.Max();
                for (int i = 0; i < 26; i++)
                {
                    current = (char)(i + 'a');
                    if (last != current && cnt[i] > 0 && (2 * mx <= n || mx == cnt[i]))
                    {
                        last = current;
                        output.Append(current);
                        cnt[i]--;
                        break;
                    }
                }
                n--;
            }

            Console.WriteLine(output);
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base6/75
1Wrong answer0/029ms21128 KiB
2Wrong answer0/028ms21820 KiB
3Wrong answer0/327ms21500 KiB
4Wrong answer0/328ms21912 KiB
5Wrong answer0/328ms22160 KiB
6Wrong answer0/327ms22420 KiB
7Wrong answer0/341ms26256 KiB
8Wrong answer0/3171ms32316 KiB
9Accepted3/328ms23404 KiB
10Accepted3/328ms23544 KiB
11Wrong answer0/328ms23384 KiB
12Wrong answer0/328ms23280 KiB
13Wrong answer0/328ms23692 KiB
14Wrong answer0/328ms23920 KiB
15Wrong answer0/3166ms32728 KiB
16Wrong answer0/3165ms32868 KiB
17Wrong answer0/3168ms33048 KiB
18Wrong answer0/3167ms32920 KiB
19Wrong answer0/3158ms33092 KiB
20Wrong answer0/3158ms32856 KiB
21Wrong answer0/3165ms32880 KiB
22Wrong answer0/6156ms32904 KiB
23Wrong answer0/6168ms33156 KiB
24Wrong answer0/6173ms33564 KiB