4741 2023. 03. 31 10:35:48 TortelliniJr Váltakozó (75 pont) csharp Időlimit túllépés 33/75 592ms 70352 KiB
using System;
using System.Linq;
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)
            {
                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--;
                mx = cnt.Max();
            }
            Console.WriteLine(output);
        }
    }

}
Részfeladat Összpont Teszt Verdikt Idő Memória
base 33/75
1 Elfogadva 0/0 27ms 20628 KiB
2 Elfogadva 0/0 28ms 23644 KiB
3 Elfogadva 3/3 28ms 21728 KiB
4 Elfogadva 3/3 28ms 22304 KiB
5 Elfogadva 3/3 27ms 21824 KiB
6 Elfogadva 3/3 26ms 22380 KiB
7 Elfogadva 3/3 356ms 70352 KiB
8 Időlimit túllépés 0/3 592ms 30464 KiB
9 Elfogadva 3/3 28ms 24288 KiB
10 Elfogadva 3/3 28ms 24164 KiB
11 Elfogadva 3/3 32ms 31652 KiB
12 Elfogadva 3/3 32ms 31724 KiB
13 Elfogadva 3/3 32ms 31784 KiB
14 Elfogadva 3/3 34ms 31724 KiB
15 Időlimit túllépés 0/3 589ms 31332 KiB
16 Időlimit túllépés 0/3 568ms 31292 KiB
17 Időlimit túllépés 0/3 565ms 31684 KiB
18 Időlimit túllépés 0/3 583ms 31872 KiB
19 Időlimit túllépés 0/3 566ms 31824 KiB
20 Időlimit túllépés 0/3 574ms 31672 KiB
21 Időlimit túllépés 0/3 578ms 32284 KiB
22 Időlimit túllépés 0/6 575ms 32596 KiB
23 Időlimit túllépés 0/6 542ms 32648 KiB
24 Időlimit túllépés 0/6 560ms 32680 KiB