47462023-03-31 10:51:01Leventusz19Váltakozó (75 pont)csharpTime limit exceeded 33/75583ms70424 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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/028ms20760 KiB
2Accepted0/028ms23568 KiB
3Accepted3/327ms21664 KiB
4Accepted3/327ms21708 KiB
5Accepted3/327ms21952 KiB
6Accepted3/327ms21676 KiB
7Accepted3/3358ms70424 KiB
8Time limit exceeded0/3583ms30036 KiB
9Accepted3/328ms23684 KiB
10Accepted3/329ms23600 KiB
11Accepted3/332ms31368 KiB
12Accepted3/332ms31220 KiB
13Accepted3/332ms31020 KiB
14Accepted3/332ms31744 KiB
15Time limit exceeded0/3582ms31368 KiB
16Time limit exceeded0/3537ms31784 KiB
17Time limit exceeded0/3572ms31756 KiB
18Time limit exceeded0/3542ms31580 KiB
19Time limit exceeded0/3572ms31824 KiB
20Time limit exceeded0/3572ms32360 KiB
21Time limit exceeded0/3574ms31972 KiB
22Time limit exceeded0/6564ms32160 KiB
23Time limit exceeded0/6560ms32444 KiB
24Time limit exceeded0/6578ms32896 KiB