목차

LIS

ps
링크acmicpc.net/…
출처BOJ
문제 번호9702
문제명LIS
레벨골드 1
분류

가장 긴 증가하는 부분 수열

시간복잡도O(T * n^2logn)
인풋사이즈T<=?, n<=500
사용한 언어Python 3.13
제출기록37036KB / 1280ms
최고기록1020ms
해결날짜2026/01/11

풀이

코드

"""Solution code for "BOJ 9702. LIS".

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

Tags: [lis]
"""

import collections
import sys
from teflib import psutils
from teflib import seqtask


@psutils.gcj_style
def main():
    N = int(sys.stdin.readline())
    s = collections.deque(int(sys.stdin.readline()) for _ in range(N))

    answer = 0
    for _ in range(N):
        length = 0
        for l in seqtask.longest_inc_subseq_lengths_by_last_elem(s):
            if l > length:
                length = l
            answer += length
        s.popleft()

    print(answer)


if __name__ == '__main__':
    main()