47502023-03-31 10:57:39Leventusz19Váltakozó (75 pont)csharpTime limit exceeded 33/75595ms70876 KiB
using System;
using System.Linq;

namespace Váltakozó_szöveg{
    class Program{
        static void Main(){
            string str = Console.ReadLine();
            int[] a = new int[26];
            string o = "";
            foreach (char i in str) a[i - 'a']++;
            int n = str.Length;
            int m = a.Max();
            char last = '-';
            if (2 * m > n + 1){
                Console.WriteLine("-1");
                return;
            }
            while (n >= 1){
                m = a.Max();
                for(int i=0; i<26; i++){
                    if(last!=i+'a'&& a[i]>0 && (2*m<=n || m == a[i])){
                        o += (last = (char)(i + 'a'));
                        a[i]--;
                        break;
                    }
                }
                n--;
            }
            Console.WriteLine(o);
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base33/75
1Accepted0/027ms20716 KiB
2Accepted0/029ms23436 KiB
3Accepted3/328ms21708 KiB
4Accepted3/327ms22036 KiB
5Accepted3/327ms22288 KiB
6Accepted3/327ms22644 KiB
7Accepted3/3354ms70876 KiB
8Time limit exceeded0/3563ms30420 KiB
9Accepted3/329ms23624 KiB
10Accepted3/329ms24056 KiB
11Accepted3/332ms31752 KiB
12Accepted3/332ms31368 KiB
13Accepted3/332ms31740 KiB
14Accepted3/332ms31496 KiB
15Time limit exceeded0/3558ms31236 KiB
16Time limit exceeded0/3566ms31836 KiB
17Time limit exceeded0/3583ms31716 KiB
18Time limit exceeded0/3583ms31460 KiB
19Time limit exceeded0/3595ms31776 KiB
20Time limit exceeded0/3574ms32164 KiB
21Time limit exceeded0/3574ms32304 KiB
22Time limit exceeded0/6542ms32344 KiB
23Time limit exceeded0/6564ms32700 KiB
24Time limit exceeded0/6583ms32596 KiB