QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#764098#7876. Cyclic SubstringsAlphaZeAC ✓572ms923836kbC++201.4kb2024-11-20 00:15:422024-11-20 00:15:43

Judging History

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

  • [2024-11-20 00:15:43]
  • 评测
  • 测评结果:AC
  • 用时:572ms
  • 内存:923836kb
  • [2024-11-20 00:15:42]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;
 
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 6e6 + 10;
const int mod = 998244353;
void AddMod(int &p, int k) { p = (p + k) % mod; }
int n; char s[N]; 
 
struct Node {
	int len;
	int fail, ch[10];
}nd[N];
int last, tot = 1;
vector<int> g[N];
int f[N];
int ans;
 
void add(int x, int y) {
	g[x].push_back(y);
}
 
int getfail(int x, int i) {
	while (i - nd[x].len - 1 < 1 || s[i] != s[i - nd[x].len - 1]) x = nd[x].fail; 
	return x;
}
 
void insert(int i) {
	int p = getfail(last, i);
	if (!nd[p].ch[s[i] - '0']) {
		nd[++tot].len = nd[p].len + 2;
		nd[tot].fail = nd[getfail(nd[p].fail, i)].ch[s[i] - '0'];
		nd[p].ch[s[i] - '0'] = tot;
		// 先连fail边, 再连扩展状态的边. 
	}
	last = nd[p].ch[s[i] - '0'];
	if (i > n) {
		++f[last];
	}
} 
 
void dfs(int x) {
	for (auto y : g[x]) {
		dfs(y);
		f[x] += f[y];
	}
	if (nd[x].len > 0 && nd[x].len <= n) {
		int v = 1ll * f[x] * f[x] % mod;
		AddMod(ans, 1ll * nd[x].len * v % mod);
	}
}
 
int main() {
	scanf("%d%s", &n, s + 1);
//	n = strlen(s + 1);
	nd[0].fail = 1; nd[0].len = 0; add(1, 0); // 偶根 
	nd[1].len = -1; // 奇根
	last = 0; tot = 1; 
	for (int i = 1; i <= n; ++i) insert(i);
	for (int i = 1; i <= n; ++i) s[i + n] = s[i], insert(i + n);
	for (int i = 2; i <= tot; ++i) add(nd[i].fail, i);
	dfs(1); printf("%d\n", ans);
} 

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

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 7880kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 3ms
memory: 8008kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 3ms
memory: 8024kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 7ms
memory: 8012kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 7ms
memory: 7928kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 6ms
memory: 8008kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 3ms
memory: 7936kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 99ms
memory: 312816kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 344ms
memory: 923836kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 147ms
memory: 245652kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 335ms
memory: 783212kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 413ms
memory: 736236kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 240ms
memory: 493824kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 218ms
memory: 463936kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 565ms
memory: 257088kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 169ms
memory: 85000kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 572ms
memory: 393128kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 528ms
memory: 380752kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed