QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526278#7876. Cyclic Substringsrxzfn639WA 2ms16108kbC++232.1kb2024-08-21 12:54:492024-08-21 12:54:53

Judging History

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

  • [2024-08-21 12:54:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:16108kb
  • [2024-08-21 12:54:49]
  • 提交

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 {
	int t[N];
	int tot, lst = 0;
	int fa[N], len[N], tr[N][31], cnt[N], dep[N], pos[N];
#define sfor(x, i) for(int i = 0; i <= 30; ++i) if(tr[x][i])
	PAM() {
		len[1] = -1, len[0] = 0;
		fa[0] = 1;
		fa[1] = 1;
		dep[1] = dep[0] = 0;
		tot = 1, lst = 1;
	}
	void init() {
		for(int i = 0; i <= tot; ++i) {
			fa[i] = len[i] = dep[i];
		}
		tot = 1, lst = 1;
		len[1] = -1, len[0] = 0;
		fa[0] = 1;
		fa[1] = 1;
		dep[1] = dep[0] = 0;
	}
	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;
		pos[lst] = i;
		cnt[lst]++;
		dep[lst] = dep[fa[lst]] + 1;
	}
	void sum() {
		for(int i = tot; i >= 0; --i) {
			cnt[fa[i]] += cnt[i];
		}
	}
}pam;
const ll mod = 998244353;

char s[N];
int 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){
		pam.extend(s[i] - '0' + 1, i);
	}

	ll ans = 0;
	pam.sum();
	rep(i, 2, pam.tot){
		if(pam.pos[i] <= n) pam.cnt[i] = (pam.cnt[i] + 1) / 2;
		if(pam.len[i] > n) continue;
		ans = 1ll * (ans + 1ll * pam.len[i] * pam.cnt[i] % mod * pam.cnt[i] % mod) % mod;
	}
	pprint(ans);
}
/*
5
01010
*/
/*
8
00110011
*/

詳細信息

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 2ms
memory: 16092kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 2ms
memory: 15892kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 16016kb

input:

3
666

output:

39

result:

wrong answer 1st numbers differ - expected: '54', found: '39'