QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526469#7876. Cyclic SubstringsAmiyaCastAC ✓172ms947112kbC++142.0kb2024-08-21 16:35:092024-08-21 16:35:09

Judging History

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

  • [2024-08-21 16:35:09]
  • 评测
  • 测评结果:AC
  • 用时:172ms
  • 内存:947112kb
  • [2024-08-21 16:35:09]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii make_pair
#define int long long
#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, int k) { //插入节点
		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;
		if(k == 1) cnt[lst]++;
	}
	void sum() {
		for(int i = tot; i >= 0; --i) {
			cnt[fa[i]] += cnt[i];
		}
	}
}pam2;
const ll mod = 998244353;

char s[N];
signed main() {
	int n = read();
	scanf("%s", s + 1);
	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, (i > n));
	}
	pam2.sum();
	ll ans = 0;
	rep(i, 2, pam2.tot){

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

	pprint(ans % mod);
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 31ms
memory: 329424kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 79ms
memory: 947112kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

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

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 123ms
memory: 947112kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 103ms
memory: 946920kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 172ms
memory: 837988kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 171ms
memory: 870540kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 152ms
memory: 504848kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 107ms
memory: 195084kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 152ms
memory: 809364kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 155ms
memory: 790700kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed