QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272568 | #7876. Cyclic Substrings | ucup-team191# | AC ✓ | 154ms | 475668kb | C++14 | 1.6kb | 2023-12-02 17:52:10 | 2023-12-02 17:52:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef pair <int, int> pi;
const int MAXN = 6000005;
const int MOD = 998244353;
int n;
string s;
int a[MAXN];
int cnt, curr;
int ch[MAXN][10];
int len[MAXN], suf[MAXN], val[MAXN];
llint sum[MAXN];
void init () {
cnt = 2; curr = 1;
len[1] = -1; suf[1] = 1;
len[2] = 0; suf[2] = 1;
}
void ubaci (int i, int c) {
while (i - len[curr] - 1 < 0 || a[i - len[curr] - 1] != c) {
curr = suf[curr];
}
if (ch[curr][c] != 0) {
curr = ch[curr][c];
val[curr]++;
return;
}
cnt++;
len[cnt] = len[curr] + 2;
ch[curr][c] = cnt;
int tmp = suf[curr];
curr = cnt;
val[curr]++;
if (len[curr] == 1) {
suf[curr] = 2;
return;
} else if (len[curr] == 2) {
suf[curr] = ch[1][c];
return;
}
while (i - len[tmp] - 1 < 0 || a[i - len[tmp] - 1] != c) {
tmp = suf[tmp];
}
suf[curr] = ch[tmp][c];
}
llint aa[MAXN][2];
void eval (int gdje) {
llint res = 0;
for (int i = cnt; i >= 1; i--) {
sum[i] = 0;
}
for (int i = cnt; i >= 1; i--) {
sum[i] += val[i];
sum[suf[i]] += sum[i];
aa[i][gdje] = sum[i];
}
}
int main () {
init();
cin >> n >> s;
for (int i = 0; i < 2 * n; i++) {
a[i] = s[i % n] - '0';
}
for (int i = 0; i < n; i++) {
ubaci(i, a[i]);
}
eval(0);
for (int i = 0; i < n; i++) {
ubaci(i + n, a[i + n]);
}
eval(1);
llint sol = 0;
for(int i = cnt;i >= 3;i--) {
if(len[i] > n) continue;
llint kol = aa[i][1] - aa[i][0];
sol += kol * kol % MOD * len[i] % MOD;
sol %= MOD;
}
cout << sol << endl;
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 13680kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 2ms
memory: 13568kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 0ms
memory: 13764kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 13820kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 2ms
memory: 13616kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 13580kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 2ms
memory: 13632kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: 0
Accepted
time: 32ms
memory: 171004kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
496166704
result:
ok 1 number(s): "496166704"
Test #9:
score: 0
Accepted
time: 154ms
memory: 475000kb
input:
3000000 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...
output:
890701718
result:
ok 1 number(s): "890701718"
Test #10:
score: 0
Accepted
time: 120ms
memory: 240760kb
input:
3000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
224009870
result:
ok 1 number(s): "224009870"
Test #11:
score: 0
Accepted
time: 120ms
memory: 475020kb
input:
3000000 8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...
output:
51985943
result:
ok 1 number(s): "51985943"
Test #12:
score: 0
Accepted
time: 112ms
memory: 475668kb
input:
3000000 1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...
output:
355676465
result:
ok 1 number(s): "355676465"
Test #13:
score: 0
Accepted
time: 119ms
memory: 429024kb
input:
3000000 7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
output:
788510374
result:
ok 1 number(s): "788510374"
Test #14:
score: 0
Accepted
time: 140ms
memory: 446996kb
input:
3000000 5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
691884476
result:
ok 1 number(s): "691884476"
Test #15:
score: 0
Accepted
time: 115ms
memory: 262972kb
input:
3000000 0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...
output:
701050848
result:
ok 1 number(s): "701050848"
Test #16:
score: 0
Accepted
time: 92ms
memory: 105100kb
input:
3000000 2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...
output:
486861605
result:
ok 1 number(s): "486861605"
Test #17:
score: 0
Accepted
time: 141ms
memory: 417472kb
input:
3000000 4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...
output:
450625621
result:
ok 1 number(s): "450625621"
Test #18:
score: 0
Accepted
time: 111ms
memory: 405764kb
input:
3000000 1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...
output:
649551870
result:
ok 1 number(s): "649551870"
Extra Test:
score: 0
Extra Test Passed