95232024-02-22 14:19:51Leventusz09Váltakozó (75 pont)csharpWrong answer 39/75601ms32876 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];

            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, v; i>0; i--){
                max = C.Max();
                for(j=0; j<26; j++){
                    v = C[j];
                    if(v>0 && last != j) if( max <= i/2 || max == v ){
                        C[j]--;
                        Console.Write((char)(j+97));
                        //o1 += (char)(j + 97);
                        last = j;
                        break;
                    }
                }
            }
            //Console.WriteLine(o1);
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base39/75
1Accepted0/027ms20976 KiB
2Accepted0/028ms21324 KiB
3Accepted3/328ms21652 KiB
4Accepted3/329ms22044 KiB
5Accepted3/327ms22116 KiB
6Accepted3/327ms22608 KiB
7Wrong answer0/327ms23316 KiB
8Wrong answer0/329ms24020 KiB
9Accepted3/328ms24164 KiB
10Accepted3/328ms24252 KiB
11Accepted3/330ms23224 KiB
12Accepted3/330ms23268 KiB
13Accepted3/330ms23528 KiB
14Accepted3/330ms23456 KiB
15Time limit exceeded0/3601ms11756 KiB
16Time limit exceeded0/3515ms32536 KiB
17Accepted3/3499ms32808 KiB
18Time limit exceeded0/3561ms12000 KiB
19Time limit exceeded0/3533ms32688 KiB
20Time limit exceeded0/3546ms32876 KiB
21Time limit exceeded0/3541ms32796 KiB
22Accepted6/6469ms32580 KiB
23Time limit exceeded0/6527ms32828 KiB
24Time limit exceeded0/6541ms32576 KiB