47082023-03-31 09:49:09TortelliniJrVáltakozó (75 pont)csharpWrong answer 6/75583ms33736 KiB
using System;

namespace Valtakozz
{
    using System;
    using System.Linq;

    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;
            }

            while (n >= 1)
            {
                mx = cnt.Max();
                for (int i = 0; i < 26; i++)
                {
                    if (last != (char)(i) && cnt[i] > 0)
                    {
                        if (2 * mx <= n || mx == cnt[i])
                        {
                            Console.Write(last = (char)(i));
                            cnt[i]--;
                            break;
                        }
                    }
                }

                n--;
            }

            Console.WriteLine();
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base6/75
1Wrong answer0/028ms21012 KiB
2Wrong answer0/029ms21352 KiB
3Wrong answer0/326ms21884 KiB
4Wrong answer0/328ms22056 KiB
5Wrong answer0/327ms22076 KiB
6Wrong answer0/327ms22492 KiB
7Wrong answer0/379ms23968 KiB
8Time limit exceeded0/3570ms11080 KiB
9Accepted3/328ms24260 KiB
10Accepted3/329ms24544 KiB
11Wrong answer0/332ms23528 KiB
12Wrong answer0/332ms23528 KiB
13Wrong answer0/332ms23820 KiB
14Wrong answer0/332ms23796 KiB
15Time limit exceeded0/3522ms12144 KiB
16Time limit exceeded0/3583ms11984 KiB
17Wrong answer0/3490ms33052 KiB
18Time limit exceeded0/3572ms12820 KiB
19Time limit exceeded0/3564ms33292 KiB
20Time limit exceeded0/3560ms12784 KiB
21Time limit exceeded0/3565ms33736 KiB
22Time limit exceeded0/6560ms12948 KiB
23Time limit exceeded0/6572ms13340 KiB
24Time limit exceeded0/6555ms13244 KiB