47212023-03-31 10:01:00TortelliniJrVáltakozó (75 pont)csharpWrong answer 21/75565ms34392 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;
            }
            char current;
            for (int i = n; i > 0; i--)
            {
                mx = cnt.Max();
                for (int u = 0; u < 26; u++)
                {
                    current = (char)(u + 'a');
                    if (last != current && cnt[u] > 0 && (2 * mx <= n || mx == cnt[u]))
                    {
                        Console.Write(last = current);
                        cnt[u]--;
                        break;
                    }
                }
            }

            Console.WriteLine();
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base21/75
1Wrong answer0/028ms20516 KiB
2Wrong answer0/029ms21172 KiB
3Accepted3/327ms21700 KiB
4Accepted3/327ms22108 KiB
5Accepted3/326ms21888 KiB
6Accepted3/326ms22456 KiB
7Accepted3/382ms23932 KiB
8Time limit exceeded0/3555ms32208 KiB
9Accepted3/329ms24484 KiB
10Accepted3/328ms24340 KiB
11Wrong answer0/330ms24032 KiB
12Wrong answer0/332ms23880 KiB
13Wrong answer0/330ms23676 KiB
14Wrong answer0/330ms24080 KiB
15Time limit exceeded0/3560ms12568 KiB
16Time limit exceeded0/3554ms12576 KiB
17Time limit exceeded0/3554ms12480 KiB
18Time limit exceeded0/3519ms33088 KiB
19Time limit exceeded0/3561ms12328 KiB
20Time limit exceeded0/3565ms12772 KiB
21Time limit exceeded0/3544ms33836 KiB
22Wrong answer0/6474ms34032 KiB
23Time limit exceeded0/6509ms34152 KiB
24Wrong answer0/6465ms34392 KiB