← Home
For problem statement at 1000-1999/1900-1999/1910-1919/1910/problemI.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1910-1919/1910/verifierI.go ends with All tests passed can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"os"
)

const MOD = 998244353

func power(base, exp int64) int64 {
	res := int64(1)
	base %= MOD
	for exp > 0 {
		if exp%2 == 1 {
			res = (res * base) % MOD
		}
		base = (base * base) % MOD
		exp /= 2
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, k, c int
	fmt.Fscan(reader, &n, &k, &c)
	var t string
	fmt.Fscan(reader, &t)

	q := n / k
	m := n % k

	powB := make([]int64, q+1)
	powB1 := make([]int64, q+1)
	DP := make([]int64, q+1)
	NewDP := make([]int64, q+1)

	v1 := int64(t[0] - 'a' + 1)
	B1 := int64(c) - v1

	powB[0] = 1
	powB1[0] = 1
	for x := 1; x <= q; x++ {
		powB[x] = (powB[x-1] * B1) % MOD
		powB1[x] = (powB1[x-1] * (B1 + 1)) % MOD
	}

	for x := 0; x <= q; x++ {
		DP[x] = (powB[x] * powB1[q-x]) % MOD
	}

	for j := 1; j < m; j++ {
		v := int64(t[j] - 'a' + 1)
		B := int64(c) - v

		powB1[0] = 1
		for x := 1; x <= q; x++ {
			powB1[x] = (powB1[x-1] * (B + 1)) % MOD
		}

		S := int64(0)
		C_pow := int64(1)

		for x := 0; x <= q; x++ {
			term1 := (S * B) % MOD
			term2 := (DP[x] * C_pow) % MOD
			S = (term1 + term2) % MOD
			NewDP[x] = (S * powB1[q-x]) % MOD
			C_pow = (C_pow * int64(c)) % MOD
		}

		for x := 0; x <= q; x++ {
			DP[x] = NewDP[x]
		}
	}

	ans := int64(0)
	for x := 0; x <= q; x++ {
		ans = (ans + DP[x]) % MOD
	}

	factor := power(int64(c), int64(q)*int64(k-m))
	ans = (ans * factor) % MOD

	fmt.Println(ans)
}