47452023-03-31 10:49:55Leventusz19Váltakozó (75 pont)csharpTime limit exceeded 6/75586ms33148 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;
                    }
                }
            }
            Console.WriteLine(o);
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base6/75
1Time limit exceeded0/0560ms8560 KiB
2Time limit exceeded0/0565ms8912 KiB
3Time limit exceeded0/3569ms8996 KiB
4Time limit exceeded0/3578ms9224 KiB
5Time limit exceeded0/3569ms9580 KiB
6Time limit exceeded0/3565ms9952 KiB
7Time limit exceeded0/3579ms30060 KiB
8Time limit exceeded0/3578ms30468 KiB
9Accepted3/330ms23992 KiB
10Accepted3/328ms24284 KiB
11Time limit exceeded0/3559ms11028 KiB
12Time limit exceeded0/3574ms11096 KiB
13Time limit exceeded0/3569ms11212 KiB
14Time limit exceeded0/3574ms11328 KiB
15Time limit exceeded0/3586ms31416 KiB
16Time limit exceeded0/3566ms31352 KiB
17Time limit exceeded0/3550ms31384 KiB
18Time limit exceeded0/3570ms31780 KiB
19Time limit exceeded0/3566ms32088 KiB
20Time limit exceeded0/3563ms32184 KiB
21Time limit exceeded0/3563ms32452 KiB
22Time limit exceeded0/6579ms32540 KiB
23Time limit exceeded0/6566ms32644 KiB
24Time limit exceeded0/6583ms33148 KiB