47292023-03-31 10:16:40TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 33/75596ms70440 KiB
using System;
using System.Linq;
using System.Collections.Generic;
namespace Valtakozz
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine().Trim();
            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;
            }
            while (n >= 1)
            {
                mx = cnt.Max();
                for (int i = 0; i < 26; i++)
                {
                    if (last != (char)(i + 'a') && cnt[i] > 0 && (2 * mx <= n || mx == cnt[i]))
                    {
                        last = (char)(i + 'a');
                        output += last;
                        cnt[i]--;
                        break;
                    }
                }
                n--;
            }
            Console.WriteLine(output);
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base33/75
1Accepted0/027ms21176 KiB
2Accepted0/028ms23536 KiB
3Accepted3/328ms21980 KiB
4Accepted3/327ms22008 KiB
5Accepted3/328ms22544 KiB
6Accepted3/328ms22452 KiB
7Accepted3/3423ms70440 KiB
8Time limit exceeded0/3588ms30640 KiB
9Accepted3/330ms23892 KiB
10Accepted3/329ms24012 KiB
11Accepted3/334ms31324 KiB
12Accepted3/332ms31512 KiB
13Accepted3/334ms31580 KiB
14Accepted3/334ms31720 KiB
15Time limit exceeded0/3578ms31736 KiB
16Time limit exceeded0/3596ms31588 KiB
17Time limit exceeded0/3592ms32088 KiB
18Time limit exceeded0/3579ms32404 KiB
19Time limit exceeded0/3570ms32592 KiB
20Time limit exceeded0/3542ms32816 KiB
21Time limit exceeded0/3579ms32968 KiB
22Time limit exceeded0/6579ms32784 KiB
23Time limit exceeded0/6578ms32852 KiB
24Time limit exceeded0/6559ms32812 KiB