사용자 도구

사이트 도구


ps:problems:boj:1620

나는야 포켓몬 마스터 이다솜

ps
링크acmicpc.net/…
출처BOJ
문제 번호1620
문제명나는야 포켓몬 마스터 이다솜
레벨실버 4
분류

기초

시간복잡도O(n+m)
인풋사이즈n<=100,000, m<=100,000
사용한 언어Python
제출기록49548KB / 248ms
최고기록188ms
해결날짜2021/07/24
태그

[라이] 이진 검색 트리

풀이

  • 이름으로부터 번호를 매핑하는 dict를 만들어서 처리하면 된다. 총 시간복잡도는 O(n+m)

코드

"""Solution code for "BOJ 1620. 나는야 포켓몬 마스터 이다솜".

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

import sys


def main():
    N, M = [int(x) for x in sys.stdin.readline().split()]
    pokemons = [sys.stdin.readline().rstrip() for _ in range(N)]
    num_by_pokemon = {x: i for i, x in enumerate(pokemons, start=1)}
    for _ in range(M):
        inp = sys.stdin.readline().rstrip()
        if inp.isdigit():
            print(pokemons[int(inp) - 1])
        else:
            print(num_by_pokemon[inp])


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
H H Z P S
 
ps/problems/boj/1620.txt · 마지막으로 수정됨: 2022/07/05 02:28 저자 teferi