사용자 도구

사이트 도구


ps:problems:boj:6574

새로운 과일

ps
링크acmicpc.net/…
출처BOJ
문제 번호6574
문제명새로운 과일
레벨골드 2
분류

lcs

시간복잡도O(nm/w)
인풋사이즈n<=100, m<=100
사용한 언어Python 3.13
제출기록32412KB / 36ms
최고기록32ms
해결날짜2026/02/20

풀이

코드

"""Solution code for "BOJ 6574. 새로운 과일".

- Problem link: https://www.acmicpc.net/problem/6574
- Solution link: http://www.teferi.net/ps/problems/boj/6574

Tags: [lcs]
"""

import sys
from teflib import psutils
from teflib import string


def shortest_common_supersequence(str_a, str_b):
    ret = []
    a_ind = b_ind = 0
    for c in string.longest_common_subseq(str_a, str_b):
        a_prev, a_ind = a_ind, str_a.find(c, a_ind) + 1
        b_prev, b_ind = b_ind, str_b.find(c, b_ind) + 1
        ret.append(str_a[a_prev : a_ind - 1])
        ret.append(str_b[b_prev:b_ind])
    ret.append(str_a[a_ind:])
    ret.append(str_b[b_ind:])
    return ''.join(ret)


@psutils.run_until_eof
def main():
    str_a, str_b = sys.stdin.readline().split()
    print(shortest_common_supersequence(str_a, str_b))


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
C​ F R X K
 
ps/problems/boj/6574.txt · 마지막으로 수정됨: 2026/02/20 06:30 저자 teferi