47272023-03-31 10:09:41TortelliniJrVáltakozó (75 pont)csharpWrong answer 6/75163ms33748 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;
            }
            char current = '-';
            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.Append((char)(i + 'a'));
                        cnt[i]--;
                        break;
                    }
                }
                n--;
            }
            Console.WriteLine(output);
        }
    }

}
SubtaskSumTestVerdictTimeMemory
base6/75
1Wrong answer0/028ms20848 KiB
2Wrong answer0/028ms21656 KiB
3Wrong answer0/328ms22076 KiB
4Wrong answer0/328ms22304 KiB
5Wrong answer0/328ms22016 KiB
6Wrong answer0/328ms22752 KiB
7Wrong answer0/341ms26196 KiB
8Wrong answer0/3162ms32204 KiB
9Accepted3/329ms23472 KiB
10Accepted3/329ms23848 KiB
11Wrong answer0/329ms23516 KiB
12Wrong answer0/328ms23344 KiB
13Wrong answer0/328ms23756 KiB
14Wrong answer0/328ms23832 KiB
15Wrong answer0/3158ms32744 KiB
16Wrong answer0/3158ms32864 KiB
17Wrong answer0/3160ms33168 KiB
18Wrong answer0/3159ms33320 KiB
19Wrong answer0/3151ms33692 KiB
20Wrong answer0/3153ms33480 KiB
21Wrong answer0/3158ms33320 KiB
22Wrong answer0/6153ms33392 KiB
23Wrong answer0/6157ms33748 KiB
24Wrong answer0/6163ms33744 KiB