사용자 도구

사이트 도구


ps:problems:boj:15829

Hashing

ps
링크acmicpc.net/…
출처BOJ
문제 번호15829
문제명Hashing
레벨브론즈 2
분류

기초

시간복잡도O(n)
인풋사이즈n<=50
사용한 언어Python
제출기록29200KB / 72ms
최고기록56ms
해결날짜2021/10/13

풀이

  • 그냥 시키는대로 구현하면 되는 문제. 설명할 것이 따로 없다.
  • 시간 복잡도는 O(n)

코드

"""Solution code for "BOJ 15829. Hashing".

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

R = 31
M = 1234567891


def main():
    L = int(input())  # pylint: disable=unused-variable
    s = input()
    h = 0
    ch_map = {ch: i for i, ch in enumerate('abcdefghijklmnopqrstuvwxyz', 1)}
    for ch in reversed(s):
        h = (h * R + ch_map[ch]) % M
    print(h)


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
Y C P Z N
 
ps/problems/boj/15829.txt · 마지막으로 수정됨: 2021/10/13 14:38 저자 teferi