QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526306#7876. Cyclic SubstringsAmiyaCastAC ✓157ms720300kbC++142.2kb2024-08-21 13:12:552024-08-21 13:12:55

Judging History

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

  • [2024-08-21 13:12:55]
  • 评测
  • 测评结果:AC
  • 用时:157ms
  • 内存:720300kb
  • [2024-08-21 13:12:55]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=b;i>=a;--i)
const ll inf = 1145141919810;
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0' || c>'9'){
        if (c=='-')  f=-1;
        c=getchar();
    }
    while (c>='0' && c<='9'){
        x=x*10+c-'0';
         c=getchar();
    }
    return x*f;
}
inline void print(ll x){
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
	return ;
}
inline void pprint(ll x){print(x); puts("");}

const int N = 6e6 + 7;
struct PAM {
    //功能多但是开多了就炸
	//时间复杂度O(n)
	//注意extent传入整数
	int t[N];//cnt表示出现次数
	int tot, lst = 0;
	int fa[N], len[N], tr[N][15], cnt[N], pos[N];
#define sfor(x, i) for(int i = 0; i <= 14; ++i) if(tr[x][i])
	PAM() {
		len[1] = -1, len[0] = 0;
		fa[0] = 1;
		fa[1] = 1;
		tot = 1, lst = 1;
	}
	int getfail(int x, int i) {
		while(t[i - len[x] - 1] != t[i]) {
			x = fa[x];
		}
		return x;
	}
	void extend(int x, int i) { //插入节点
		t[i] = x;
		int f = getfail(lst, i);//找要接在哪个节点下面
		int j = tr[f][x];
		if(!j) {
			j = ++tot;
			tr[f][x] = j;
			len[j] = len[f]+2;
			int tmp = getfail(fa[f], i);
			if(f != 1) fa[j] = tr[tmp][x];
		}
		lst = j;//更新lst
//		cout << lst << endl;
		if(!pos[lst]) pos[lst] = i;
		cnt[lst]++;
	}
	void sum() {
		for(int i = tot; i >= 0; --i) {
			cnt[fa[i]] += cnt[i];
		}
	}
}pam1, pam2;
const ll mod = 998244353;

char s[N];
int main() {
	int n = read();
	scanf("%s", s + 1);
	for(int i = 1; i <= n; ++i){
		pam1.extend(s[i] - '0' + 1, i);
	}
	for(int i = n + 1; i <= 2 * n; ++i) s[i] = s[i - n];
	for(int i = 1; i <= n * 2; ++i){
		pam2.extend(s[i] - '0' + 1, i);
	}
	ll ans1 = 0, ans2 = 0, ans = 0;

	pam1.sum();
	pam2.sum();


	rep(i, 2, pam2.tot){

		if(pam2.len[i] > n) continue;
		ll cnt = pam2.cnt[i] - pam1.cnt[i];
		ans = 1ll * (ans + 1ll * pam2.len[i] * cnt % mod * cnt % mod) % mod;
	}

	pprint(ans % mod);
}
/*
5
01010
*/
/*
8
00110011
*/
/*
3
000
*/

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 20136kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 0ms
memory: 20004kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 0ms
memory: 20216kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 20132kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 0ms
memory: 20216kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 0ms
memory: 20156kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 40ms
memory: 254836kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 139ms
memory: 719752kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 135ms
memory: 429940kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 132ms
memory: 718956kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 134ms
memory: 720300kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 157ms
memory: 629464kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 115ms
memory: 642888kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 120ms
memory: 498980kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 88ms
memory: 186304kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 116ms
memory: 588800kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 135ms
memory: 569864kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed