====== Hashing ====== ===== 풀이 ===== * 그냥 시키는대로 구현하면 되는 문제. 설명할 것이 따로 없다. * 시간 복잡도는 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() {{tag>BOJ ps:problems:boj:브론즈_2}}