QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#167754#7187. Hardcore String Countingucup-team866#AC ✓3439ms55252kbC++142.9kb2023-09-07 17:09:012023-09-07 17:09:01

Judging History

你现在查看的是最新测评结果

  • [2023-09-07 17:09:01]
  • 评测
  • 测评结果:AC
  • 用时:3439ms
  • 内存:55252kb
  • [2023-09-07 17:09:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20 | 1, MOD = 998244353;
int n, m, a[N], _l, _d, l, p, _x[N], x[N], tmp[N];
int * g[N], M[N], I[N], X[N], T[N], ans, _a[N], _b[N], _c[N], f[N], ia[N], q[N];
int nxt[N]; char s[N];
int PLUS(int x, int y) { return (x += y) >= MOD ? x - MOD : x; }
int qpow(int x, int y) { int t = 1; for (; y; y>>=1) { if (y & 1) t = 1ll * t * x % MOD; x = 1ll * x * x % MOD; } return t; }
void NTT(int n, int *a, bool o) {
	for (int i=0; i<n; i++)
		if (i < f[i]) swap(a[i], a[f[i]]);
	for (int i=1, _; i<n; i<<=1)
		for (int j=0; j<n; j+=i<<1)
			for (int k=j; k<j+i; k++)
				_ = 1ll * g[i][k-j] * a[k+i] % MOD, a[k+i] = PLUS(a[k], MOD - _), a[k] = PLUS(a[k], _);
	if (o) {
		reverse (a+1, a+n);
		int inv = qpow(n, MOD - 2);
		for (int i=0; i<n; i++) a[i] = 1ll * a[i] * inv % MOD;
	}
}
void mul(int n, int *a, int m, int *b, int l, int *c) {
	int len = 1;
	while (len < n + m - 1) len <<= 1;
	for (int i=0; i<len; i++) _a[i] = i < n ? a[i] : 0, _b[i] = i < m ? b[i] : 0, f[i] = f[i>>1] >> 1 | (i & 1 ? len >> 1 : 0);
	NTT(len, _a, 0), NTT(len, _b, 0);
	for (int i=0; i<len; i++) _a[i] = 1ll * _a[i] * _b[i] % MOD;
	NTT(len, _a, 1);
	for (int i=0; i<l; i++) c[i] = _a[i];
}
void inv(int n, int *a, int *b) {
	int m = 1; while (m < n) m <<= 1;
	ia[0] = qpow(a[0], MOD - 2);
	for (int i=2; i<=m; i<<=1) {
		mul(i, a, i>>1, ia, i, tmp);
		for (int j=0; j<i; j++) tmp[j] = PLUS(j ? 0 : 2, MOD - tmp[j]);
		mul(i, tmp, i>>1, ia, i, ia);
	}
	for (int i=0; i<n; i++) b[i] = ia[i];
}
void mulmod(int *a, int *b) {
	mul(l, a, l, b, (l<<1)-1, a);
	reverse (a, a+(l<<1)-1);
	mul(l-1, a, l-1, I, l-1, q);
	reverse (a, a+(l<<1)-1);
	reverse (q, q+l-1);
	mul(l+1, M, l-1, q, (l<<1)-1, q);
	for (int i=0; i<(l<<1)-1; i++)
		a[i] = PLUS(a[i], MOD - q[i]);
}
int main() {
	scanf ("%d%d%s", &n, &m, s+1);
	if (n == 1) {
		ans = 1;
		while (-- m) ans = 25ll * ans % MOD;
		return cout << ans, 0;
	}
	for (int i=2, k=0; i<=n; i++) {
		while (k && s[k+1] != s[i]) k = nxt[k];
		if (s[k+1] == s[i]) k ++;
		nxt[i] = k;
	}
	x[1] = 26;
	for (int i=nxt[n]; i; i=nxt[i])
		x[n-i] = PLUS(x[n-i], MOD - 1), x[n-i+1] = PLUS(x[n-i+1], 26);
	x[n] = PLUS(x[n], MOD - 1);
	a[0] = MOD - 1;
	for (int i=1; i<=n; i++)
		a[i] = 26ll * a[i-1] % MOD;
	l = n;
	for (int i=1; i<1<<18; i<<=1) {
		g[i] = new int [i] {1};
		if (i > 1) {
			g[i][1] = qpow(3, (MOD - 1) / (i << 1));
			for (int j=2; j<i; j++) g[i][j] = 1ll * g[i][j-1] * g[i][1] % MOD;
		}
	}
	for (int i=1; i<=l; i++)
		M[l-i] = x[i] = PLUS(MOD - x[i], 0);
	M[l] = x[0] = 1;
	inv(l-1, x, I);
	X[1] = T[0] = 1;
	for (m--; m; m>>=1) {
		if (m & 1) mulmod(T, X);
		mulmod(X, X);
	}
	for (int i=0; i<l; i++)
		ans = (ans + 1ll * T[i] * (MOD - a[i+1])) % MOD;
	memset (X, 0, sizeof X), X[1] = 1;
	mulmod(T, X);
	for (int i=0; i<l; i++)
		ans = (ans + 1ll * T[i] * a[i]) % MOD;
	cout << ans;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 33400kb

input:

6 7
aaaaaa

output:

25

result:

ok answer is '25'

Test #2:

score: 0
Accepted
time: 1ms
memory: 33392kb

input:

3 5
aba

output:

675

result:

ok answer is '675'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5704kb

input:

1 1
a

output:

1

result:

ok answer is '1'

Test #4:

score: 0
Accepted
time: 1ms
memory: 33432kb

input:

5 7
ababa

output:

675

result:

ok answer is '675'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5764kb

input:

1 3
a

output:

625

result:

ok answer is '625'

Test #6:

score: 0
Accepted
time: 4ms
memory: 33500kb

input:

10 536870912
njjnttnjjn

output:

826157401

result:

ok answer is '826157401'

Test #7:

score: 0
Accepted
time: 1589ms
memory: 54824kb

input:

65535 536870912
aaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaaeaaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaaeaaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaaeaaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaayaaaoaaaoaaaoaaaraaaoaaaoaaaoaaayaaaoaaaoaaao...

output:

996824286

result:

ok answer is '996824286'

Test #8:

score: 0
Accepted
time: 3434ms
memory: 40740kb

input:

99892 536870912
wwwwbwwwwbwwwwqwwwwbwwwwbwwwwqwwwwbwwwwbwwwweewwwwbwwwwbwwwwqwwwwbwwwwbwwwwqwwwwbwwwwbwwwweewwwwbwwwwbwwwwqwwwwbwwwwbwwwwqwwwwbwwwwbwwwwawwwwbwwwwbwwwwqwwwwbwwwwbwwwwqwwwwbwwwwbwwwweewwwwbwwwwbwwwwqwwwwbwwwwbwwwwqwwwwbwwwwbwwwweewwwwbwwwwbwwwwqwwwwbwwwwbwwwwqwwwwbwwwwbwwwwawwwwbwwwwb...

output:

718505966

result:

ok answer is '718505966'

Test #9:

score: 0
Accepted
time: 3439ms
memory: 34552kb

input:

100000 536870912
rrmrrqrrmrrcrrmrrqrrmrrbrrmrrqrrmrrcrrmrrqrrmrrnnrrmrrqrrmrrcrrmrrqrrmrrbrrmrrqrrmrrcrrmrrqrrmrrttrrmrrqrrmrrcrrmrrqrrmrrbrrmrrqrrmrrcrrmrrqrrmrrnnrrmrrqrrmrrcrrmrrqrrmrrbrrmrrqrrmrrcrrmrrqrrmrrarrmrrqrrmrrcrrmrrqrrmrrbrrmrrqrrmrrcrrmrrqrrmrrnnrrmrrqrrmrrcrrmrrqrrmrrbrrmrrqrrmrrcrrm...

output:

824845147

result:

ok answer is '824845147'

Test #10:

score: 0
Accepted
time: 3037ms
memory: 34620kb

input:

99892 1000000000
ggggjggggjggggxggggjggggjggggxggggjggggjggggeeggggjggggjggggxggggjggggjggggxggggjggggjggggeeggggjggggjggggxggggjggggjggggxggggjggggjggggbggggjggggjggggxggggjggggjggggxggggjggggjggggeeggggjggggjggggxggggjggggjggggxggggjggggjggggeeggggjggggjggggxggggjggggjggggxggggjggggjggggbggggjgggg...

output:

971128221

result:

ok answer is '971128221'

Test #11:

score: 0
Accepted
time: 2525ms
memory: 34476kb

input:

100000 625346716
kwfuguxrbiwlvyqsbujelgcafpsnxsgefwxqoeeiwoolreyxvaahagoibdrznebsgelthdzqwxcdglvbpawhdgaxpiyjglzhiamhtptsyyzyyhzjvnqfyqhnrtbwgeyotmltodidutmyvzfqfctnqugmrdtuyiyttgcsjeupuuygwqrzfibxhaefmbtzfhvopmtwwycopheuacgwibxlsjpupdmchvzneodwuzzteqlzlfizpleildqqpcuiechcwearxlvplatyrzxfochdfjqcmzt...

output:

0

result:

ok answer is '0'

Test #12:

score: 0
Accepted
time: 1156ms
memory: 54656kb

input:

65536 35420792
pkmyknsqmhwuevibxjgrftrinkulizarxbkmgorddvuvtrhdadnlxfrxsyqhueuefdkanysaixmhbdqyskjdrzntlaqtwoscxldmyzahzwximvjgsjuddejbsbwtxgkbzfzdusucccohjwjuaasnkindxjjtxdbxmitcixrcmawdezafgnigghdtoyzazyfedzsuwsrlkdtarcmzqnszgnyiqvzamjtamvfrhzucdsfscyzdbvbxutwraktnmfrdfbejcbhjcgczgwiucklwydmuuozlu...

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 3044ms
memory: 34452kb

input:

100000 1000000000
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...

output:

545362217

result:

ok answer is '545362217'

Test #14:

score: 0
Accepted
time: 3387ms
memory: 40852kb

input:

100000 536870911
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...

output:

332737929

result:

ok answer is '332737929'

Test #15:

score: 0
Accepted
time: 3390ms
memory: 34632kb

input:

100000 536870911
qodtwstdnykduvzvvvzmpawqaajvcdatuzzjisoezaqtvqhghmixvlfyhznvrlhdslyyhxoqchflfdjiefikpfrykekhjqywxpwmihiojcfzcmqelrkddbpkcnqcaopdyhldawyrvkqfbqpybewrtusifbfdtxiflxtkzdjqbocozdpupunehraytkhqnobhzeohkvbjyrdfebstqfjlvrcabimlybsnuaqgfcldvklwnyuywvfpdqwmortctexzaufmazyatybltglyonllufofiyr...

output:

592710827

result:

ok answer is '592710827'

Test #16:

score: 0
Accepted
time: 1646ms
memory: 44732kb

input:

100000 100000
ciawhxojdqnivfonswbklnoocigwmkbjtkzahqgysihfdeqhialusobeeazqaqzryakqycapfswxpithldpuiflxzpgsysjwnpinfubqlyadphswzvzbrxcdbbhavtzkvwrcqecfnzawisgkvsopjnfzfnlecuesnffqzcknunwsxlrbvdzqbduypfrwgqqnrjstxgjaeuqxxajfbmidkwhrgkpjduftivfwnuugxomyznpbtbcstdkdaitvpdtuvyzipygztosvjwwdascbqthqdgkbit...

output:

1

result:

ok answer is '1'

Test #17:

score: 0
Accepted
time: 2955ms
memory: 55252kb

input:

100000 1000000000
zujpixywgppdzqtwikoyhvlwqvxrfdylopuqgprrqpgqmgfkmhbucwkgdljyfzzbtaxxnltmbptwhknjjqlbeuiowdblqppqeeuunexkghdxjtbidlacmycgwvulgaeazyiwzedaxhtskacflodouylwxfjydzfbthotdwrfcpwrkcgnxpjsmkafaaojlctmqckabidgalvptziemzphncrgtqxlvllgwwgkoqxwhziuxvkadgaohdlceuggwwzmpywsgoecwwhhbotaleesjexdxg...

output:

879141501

result:

ok answer is '879141501'

Extra Test:

score: 0
Extra Test Passed