ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

1701๋ฒˆ: Cubeditor

Cubelover๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด Whitespace์˜ ์ฝ”๋”ฉ์„ ๋„์™€์ฃผ๋Š” ์–ธ์–ด์ธ Cubelang์„ ๋งŒ๋“ค์—ˆ๋‹ค. Cubelang์„ ์ด์šฉํ•ด ์ฝ”๋”ฉ์„ ํ•˜๋‹ค๋ณด๋‹ˆ, ์ ์  ์ด ์–ธ์–ด์— ๋งž๋Š” ์ƒˆ๋กœ์šด ์—๋””ํ„ฐ๊ฐ€ ํ•„์š”ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ์˜ค๋žœ ์‹œ๊ฐ„ ๊ณ ์ƒํ•œ

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ์ž…๋ ฅ๋œ ๋ฌธ์ž์—ด์˜ ๋‘ ๋ฒˆ ์ด์ƒ ๋‚˜์˜ค๋Š” ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ์ค‘ ๊ฐ€์žฅ ๊ธด ๊ธธ์ด๋ฅผ ์ฐพ๋Š” ๋ฌธ์ œ์ด๋‹ค. ์ด๋Š” ์•ž์„œ ๋‹ค๋ฃฌ 16916 ๋ถ€๋ถ„ ๋ฌธ์ž์—ด, 1786 ์ฐพ๊ธฐ์—์„œ ๋ฌธ์ž์—ด ์ผ์น˜์— ๋”ฐ๋ผ ์ •๋ณด๋ฅผ ์ƒ์„ฑํ•˜๋Š” `make_table`์„ ํ™œ์šฉํ•˜๋ฉด ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค.

 

์ฝ”๋“œ

def make_table(patten):
    length = len(patten)
    table = [0] * len(patten)
    j = 0
    for i in range(1, length):
        while j > 0 and patten[i] != patten[j]:
            j = table[j - 1]
        if patten[i] == patten[j]:
            j += 1
            table[i] = j
    return max(table)


if __name__ == "__main__":
    s = input()
    result = 0

    for idx in range(len(s)):
        sub_str = s[idx:len(s)]
        result = max(result, make_table(sub_str))

    print(result)

 

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€