QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#391736 | #7876. Cyclic Substrings | wtz2333 | AC ✓ | 187ms | 480444kb | C++20 | 2.1kb | 2024-04-16 18:46:24 | 2024-04-16 18:46:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mo = 998244353;
struct PAM {
static constexpr int ALPHABET_SIZE = 10;
struct Node {
int len; // 当前节点最长回文长度
int fail;// 回文树边
int scnt; // 当前节点表示的回文后缀的本质不同回文串个数
int pcnt; // 当前节点回文串在字符串中出现次数,每个点代表一个不同的回文串
std::array<int, ALPHABET_SIZE> next;
Node() : len{}, fail{}, scnt{}, next{}, pcnt{} {}
};
std::vector<Node> t;
int last;
std::string s;
PAM() {
init();
}
void init() {
t.assign(2, Node());
t[1].len = -1;
last = 0;
t[0].fail = 1;
s = "$";
}
int newNode() {
t.emplace_back();
return t.size() - 1;
}
int get_fail(int x) {
int pos = s.size() - 1;
while(s[pos - t[x].len - 1] != s[pos]) x = t[x].fail;
return x;
}
void add(char c, int w, char offset = 'a') {
s += c;
int let = c - offset;
int x = get_fail(last);
if (!t[x].next[let]) {
int now = newNode();
t[now].len = t[x].len + 2;
t[now].fail = t[get_fail(t[x].fail)].next[let];
t[x].next[let] = now;
t[now].scnt = t[t[now].fail].scnt + 1;
}
last = t[x].next[let];
t[last].pcnt += w;
}
int calc() {
int ans = 0;int n = int(s.size()) / 2;
for(int i = t.size() - 1;i >= 2;i --) {
t[t[i].fail].pcnt += t[i].pcnt;
if(t[i].len <= n)ans = (ans + 1ll * t[i].pcnt * t[i].pcnt % mo * t[i].len % mo) % mo;
}
return ans;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
PAM pam;
for(int i = 0;i < n;i ++) {
pam.add(s[i],0,'0');
}
for(int i = 0;i < n;i ++) {
pam.add(s[i],1,'0');
}
int ans = pam.calc();
cout << ans << endl;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3744kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: 0
Accepted
time: 59ms
memory: 123712kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
496166704
result:
ok 1 number(s): "496166704"
Test #9:
score: 0
Accepted
time: 144ms
memory: 479784kb
input:
3000000 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...
output:
890701718
result:
ok 1 number(s): "890701718"
Test #10:
score: 0
Accepted
time: 114ms
memory: 244820kb
input:
3000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
224009870
result:
ok 1 number(s): "224009870"
Test #11:
score: 0
Accepted
time: 142ms
memory: 479348kb
input:
3000000 8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...
output:
51985943
result:
ok 1 number(s): "51985943"
Test #12:
score: 0
Accepted
time: 131ms
memory: 478860kb
input:
3000000 1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...
output:
355676465
result:
ok 1 number(s): "355676465"
Test #13:
score: 0
Accepted
time: 187ms
memory: 480444kb
input:
3000000 7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
output:
788510374
result:
ok 1 number(s): "788510374"
Test #14:
score: 0
Accepted
time: 166ms
memory: 477988kb
input:
3000000 5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
691884476
result:
ok 1 number(s): "691884476"
Test #15:
score: 0
Accepted
time: 123ms
memory: 243856kb
input:
3000000 0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...
output:
701050848
result:
ok 1 number(s): "701050848"
Test #16:
score: 0
Accepted
time: 55ms
memory: 70952kb
input:
3000000 2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...
output:
486861605
result:
ok 1 number(s): "486861605"
Test #17:
score: 0
Accepted
time: 135ms
memory: 480364kb
input:
3000000 4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...
output:
450625621
result:
ok 1 number(s): "450625621"
Test #18:
score: 0
Accepted
time: 155ms
memory: 479104kb
input:
3000000 1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...
output:
649551870
result:
ok 1 number(s): "649551870"
Extra Test:
score: 0
Extra Test Passed