93682024-02-21 10:08:31Leventusz09Váltakozó (75 pont)csharpWrong answer 30/75577ms33072 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Váltakozó{
    class Program{
        static void Main(){
            /*string str = Console.ReadLine()
            int N = str.Length;
            int[] C = new int[26];
            int e = 0, l = 0;
            foreach (int i in str) C[i - 97]++;

            string o1 = "";

            if(C.Max() > N/2){
                Console.WriteLine(-1);
                return;
            }

            for (int i=0, last = -1; l != N; i++){
                if (i > 25) for(int j=l-1; l!= N && j>0; j--){
                    if(o1[j] != C.Max() && o1[j-1] != C.Max()){
                            o1 = o1.Substring(0, j) + (char)(C.Max()+97) + o1.Substring(j);
                            C[Array.IndexOf(C, C.Max())]--;
                            l++;
                    }
                }else
                if(C[i] > 0 && last != i){
                    C[i]--;
                    l++;
                    o1 += (char)(i + 97);
                    last = i;
                    i = e - 1;
                }else{
                    
                }
            }
            Console.WriteLine(o1);
            */

            string str = Console.ReadLine();
            int N = str.Length;
            int[] C = new int[26];
            foreach (int i in str) C[i - 97]++;
            int max = C.Max(), last = -1;
            
            if(max > N / 2) {
                Console.WriteLine(-1); return;
            }

            string o1 = "";
            for(int i=N, j; i>0; i--){
                max = C.Max();
                for(j=0; j<26; j++){
                    if(C[j]>0 && last != j) if( max <= i/2 || max == C[j] ){

                        C[j]--;
                        o1 += (char)(j + 97);
                        last = j;
                        break;
                    }
                }
            }
            Console.WriteLine(o1);
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base30/75
1Accepted0/028ms21000 KiB
2Accepted0/030ms23704 KiB
3Accepted3/328ms22052 KiB
4Accepted3/328ms22128 KiB
5Accepted3/327ms22340 KiB
6Accepted3/327ms21832 KiB
7Wrong answer0/327ms22320 KiB
8Wrong answer0/330ms23472 KiB
9Accepted3/330ms23848 KiB
10Accepted3/330ms24020 KiB
11Accepted3/332ms31188 KiB
12Accepted3/334ms31240 KiB
13Accepted3/335ms31216 KiB
14Accepted3/332ms31584 KiB
15Time limit exceeded0/3509ms31428 KiB
16Time limit exceeded0/3561ms31560 KiB
17Time limit exceeded0/3509ms31996 KiB
18Time limit exceeded0/3573ms31916 KiB
19Time limit exceeded0/3510ms32172 KiB
20Time limit exceeded0/3560ms32592 KiB
21Time limit exceeded0/3574ms32296 KiB
22Time limit exceeded0/6569ms32468 KiB
23Time limit exceeded0/6564ms33072 KiB
24Time limit exceeded0/6577ms32932 KiB