Submission #76079967


Source Code Expand

def stack_gen(arg, inf = False):
    for i, n in arg:
        for _ in range(n):yield i
    while inf:
        yield ""
    return ""
from collections import defaultdict
T = int(input())
for _ in range(T):
    S = input()
    roof = (len(S)+1)//2
    max_v = 0
    s_dic = defaultdict(int)
    for Si in S:
        s_dic[Si]+=1
        max_v = max(max_v, s_dic[Si])
        if max_v>roof:
            print("No")
            break
    else:
        print("Yes")
        s_sort = sorted(s_dic.items(), key = lambda i:i[1], reverse = True)
        outsides = []
        outside_len = 0
        for n, i in enumerate(s_sort):
            if outside_len+i[1]>roof:
                left_out = roof-outside_len
                last = (n, (i[0], i[1]-left_out))
                outsides.append((i[0], left_out))
                break
            outside_len+=i[1]
            outsides.append(i)
        s_sort[last[0]] = last[1]
        insides = s_sort[last[0]:]
        print("".join(i+jj for i, jj in zip(stack_gen(outsides), stack_gen(insides, inf = True),)))

Submission Info

Submission Time
Task D - Adjacent Distinct String
User hydroxed_sil
Language Python (PyPy 3.11-v7.3.20)
Score 0
Code Size 1090 Byte
Status RE
Exec Time 181 ms
Memory 115140 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 1
AC × 19
RE × 2
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 63 ms 93576 KiB
01_handmade_00.txt RE 131 ms 115140 KiB
01_handmade_01.txt RE 129 ms 114508 KiB
01_handmade_02.txt AC 80 ms 111100 KiB
01_handmade_03.txt AC 125 ms 112784 KiB
01_handmade_04.txt AC 126 ms 112444 KiB
01_handmade_05.txt AC 166 ms 110564 KiB
02_random_00.txt AC 129 ms 112412 KiB
02_random_01.txt AC 123 ms 112856 KiB
02_random_02.txt AC 128 ms 112400 KiB
02_random_03.txt AC 102 ms 110988 KiB
02_random_04.txt AC 105 ms 111204 KiB
02_random_05.txt AC 103 ms 110924 KiB
02_random_06.txt AC 102 ms 111012 KiB
02_random_07.txt AC 125 ms 112480 KiB
02_random_08.txt AC 181 ms 110708 KiB
02_random_09.txt AC 167 ms 110596 KiB
02_random_10.txt AC 150 ms 109924 KiB
02_random_11.txt AC 143 ms 109824 KiB
02_random_12.txt AC 128 ms 109412 KiB
02_random_13.txt AC 128 ms 109316 KiB