Advertisement
999ms

Untitled

Mar 3rd, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. n, a, b = list(map(int, input().split()))
  2. s = input()
  3. ans = 0
  4. while len(s) > 0:
  5.     l = 0
  6.     r = len(s) // 2
  7.     m = 0
  8.     ok = 0
  9.     while l <= r:
  10.         m = (l + r) // 2
  11.         if s[len(s) - m::] in s[:len(s) - m]:
  12.             ok = m
  13.             l = m + 1
  14.         else:
  15.             r = m - 1
  16.     if ok == 0:
  17.         ans += a
  18.         s = s[:-1]
  19.     else:
  20.         ans += min(ok * a, b)
  21.         s = s[:-ok]
  22. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement