Submission #50578746


Source Code Expand

import os
import sys
import gc

sys.setrecursionlimit(210000)
gc.disable()


def debug(func):
    def wrapper(*args, **kwargs):
        if os.getenv('TEST'):
            return func(*args, **kwargs)
    return wrapper


@debug
def eprint(*args, **kwargs):
    print('[EPRINT]', *args, file=sys.stderr, **kwargs)


def main() -> None:
    input()
    S = input()
    Q = int(input())
    convs = [[i] for i in range(26)]

    for _ in range(Q):
        C, D = input().split()
        c = ord(C[0]) - ord('a')
        d = ord(D[0]) - ord('a')
        if c == d:
            continue

        convs[d].extend(convs[c])
        convs[c].clear()

    table = {}
    for i, conv in enumerate(convs):
        for c in conv:
            table[chr(c + ord('a'))] = chr(i + ord('a'))

    S = ''.join([table[c] for c in S])

    print(S)


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task C - Many Replacement
User takedarts
Language Python (PyPy 3.10-v7.3.12)
Score 350
Code Size 877 Byte
Status AC
Exec Time 126 ms
Memory 85384 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 54 ms 76464 KiB
00_sample_01.txt AC 54 ms 76472 KiB
00_sample_02.txt AC 54 ms 76764 KiB
01_random_03.txt AC 125 ms 85040 KiB
01_random_04.txt AC 123 ms 85288 KiB
01_random_05.txt AC 125 ms 84920 KiB
01_random_06.txt AC 124 ms 85384 KiB
01_random_07.txt AC 123 ms 85120 KiB
01_random_08.txt AC 92 ms 83940 KiB
01_random_09.txt AC 88 ms 85160 KiB
01_random_10.txt AC 97 ms 83872 KiB
01_random_11.txt AC 115 ms 84296 KiB
01_random_12.txt AC 114 ms 84916 KiB
01_random_13.txt AC 124 ms 85356 KiB
01_random_14.txt AC 103 ms 83304 KiB
01_random_15.txt AC 123 ms 84888 KiB
01_random_16.txt AC 124 ms 84884 KiB
01_random_17.txt AC 124 ms 85312 KiB
01_random_18.txt AC 126 ms 85068 KiB
01_random_19.txt AC 121 ms 85340 KiB
01_random_20.txt AC 123 ms 85236 KiB
01_random_21.txt AC 121 ms 84872 KiB
01_random_22.txt AC 120 ms 84896 KiB
01_random_23.txt AC 88 ms 83208 KiB
01_random_24.txt AC 69 ms 82168 KiB
01_random_25.txt AC 57 ms 81048 KiB
01_random_26.txt AC 62 ms 82692 KiB
01_random_27.txt AC 54 ms 76664 KiB
01_random_28.txt AC 53 ms 76344 KiB