47172023-03-31 09:55:58TortelliniJrVáltakozó (75 pont)csharpTime limit exceeded 39/75570ms33372 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 = '-';
            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]))
                    {
                        Console.Write(last = current);
                        cnt[i]--;
                        break;
                    }
                }

                n--;
            }

            Console.WriteLine();
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base39/75
1Accepted0/028ms20708 KiB
2Accepted0/029ms21228 KiB
3Accepted3/328ms21456 KiB
4Accepted3/327ms21956 KiB
5Accepted3/327ms22456 KiB
6Accepted3/327ms22528 KiB
7Accepted3/374ms23500 KiB
8Time limit exceeded0/3568ms11408 KiB
9Accepted3/328ms24308 KiB
10Accepted3/328ms24472 KiB
11Accepted3/332ms23832 KiB
12Accepted3/332ms23956 KiB
13Accepted3/332ms23884 KiB
14Accepted3/332ms23992 KiB
15Time limit exceeded0/3546ms12544 KiB
16Time limit exceeded0/3504ms32996 KiB
17Time limit exceeded0/3570ms12408 KiB
18Time limit exceeded0/3513ms32864 KiB
19Time limit exceeded0/3559ms12172 KiB
20Time limit exceeded0/3550ms12100 KiB
21Time limit exceeded0/3555ms12160 KiB
22Time limit exceeded0/6565ms33172 KiB
23Accepted6/6492ms33372 KiB
24Time limit exceeded0/6568ms12880 KiB