We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Super Functional Strings
Super Functional Strings
Sort by
recency
|
15 Discussions
|
Please Login in order to post a comment
using p:
import sys MOD = 10**9 + 7
--- suffix array (doubling) and LCP (Kasai) ---
def build_sa(s):
def build_lcp(s, sa): n = len(s) rank = [0]*n for i, p in enumerate(sa): rank[p]=i lcp = [0]*n h = 0 for i in range(n): if rank[i] == 0: continue j = sa[rank[i]-1] while i+h < n and j+h < n and s[i+h]==s[j+h]: h+=1 lcp[rank[i]] = h if h: h-=1 return lcp
--- main solver per test string ---
def solve_one(s, powprefix): n = len(s) if n == 0: return 0 sa = build_sa(s) lcp = build_lcp(s, sa)
--- precompute power prefix sums up to global maximum n across all tests ---
def main(): data = sys.stdin.read().strip().split() if not data: return t = int(data[0]) strs = data[1:] maxn = 0 for s in strs: if len(s) > maxn: maxn = len(s) # distinct count at most 26 => we need powers k in [1..26] MAXK = 26 # powprefix[k][i] = sum_{x=1..i} x^k mod # We'll index powprefix[k] as list length maxn+1 with powprefix[k][0]=0 powprefix = [[0]*(maxn+1) for _ in range(MAXK+1)] for k in range(1, MAXK+1): acc = 0 for x in range(1, maxn+1): acc = (acc + pow(x, k, MOD)) % MOD powprefix[k][x] = acc
if name == "main": main()
Unable to understand the problem statement.
Here is my solution in java, javascript, python, c, c++, Csharp HackerRank Super Functional Strings Solution
Here is the solution of Super Functional Strings Click Here
Here is Super functional strings problem solution in python java c++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-super-functional-strings-problem-solution.html