47402023-03-31 10:33:03TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 33/75583ms70784 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/027ms20512 KiB
2Accepted0/029ms23368 KiB
3Accepted3/327ms21548 KiB
4Accepted3/326ms22136 KiB
5Accepted3/328ms22308 KiB
6Accepted3/327ms22652 KiB
7Accepted3/3421ms70784 KiB
8Time limit exceeded0/3569ms30884 KiB
9Accepted3/328ms24504 KiB
10Accepted3/329ms24644 KiB
11Accepted3/334ms31996 KiB
12Accepted3/332ms32248 KiB
13Accepted3/334ms32052 KiB
14Accepted3/332ms32412 KiB
15Time limit exceeded0/3509ms32148 KiB
16Time limit exceeded0/3574ms32608 KiB
17Time limit exceeded0/3578ms32744 KiB
18Time limit exceeded0/3579ms32704 KiB
19Time limit exceeded0/3583ms33152 KiB
20Time limit exceeded0/3559ms32904 KiB
21Time limit exceeded0/3583ms32956 KiB
22Time limit exceeded0/6583ms33288 KiB
23Time limit exceeded0/6572ms33692 KiB
24Time limit exceeded0/6561ms33636 KiB