QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#288369 | #7876. Cyclic Substrings | ckiseki# | AC ✓ | 380ms | 546992kb | C++20 | 2.7kb | 2023-12-22 16:00:25 | 2023-12-22 16:00:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#include <experimental/iterator>
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
struct PalindromicTree {
struct node {
int nxt[10], f, len;
int cnt, num;
node(int l = 0)
: nxt {}, f(0), len(l), cnt(0), num(0) {}
};
vector<node> st;
vector<char> s;
int last, n;
void init() {
st.clear(); s.clear();
last = 1; n = 0;
st.push_back(0); st.push_back(-1);
st[0].f = 1; s.push_back(-1);
}
int getFail(int x) {
while (s[n - st[x].len - 1] != s[n])
x = st[x].f;
return x;
}
void add(int c) {
s.push_back(c -= '0');
++n;
int cur = getFail(last);
if (!st[cur].nxt[c]) {
int now = (int)st.size();
st.push_back(st[cur].len + 2);
st[now].f = st[getFail(st[cur].f)].nxt[c];
st[cur].nxt[c] = now;
st[now].num = st[st[now].f].num + 1;
}
last = st[cur].nxt[c];
// ++st[last].cnt;
}
void dpcnt() {
for (int i = (int)st.size() - 1; i >= 0; i--)
st[st[i].f].cnt += st[i].cnt;
}
void clear_cnt() {
for (int i = (int)st.size() - 1; i >= 0; i--)
st[i].cnt = 0;
}
int size() { return st.size() - 2; }
} pt;
const int mod = 998244353;
int mul(int64_t a, int64_t b) {
return static_cast<int>(a * b % mod);
}
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
pt.init();
vector<int> F, S;
for (int i = 0; i < n; i++) {
pt.add(s[i]);
F.push_back(pt.last);
S.push_back(pt.last);
}
for (int i = 0; i < n; i++) {
pt.add(s[i]);
S.push_back(pt.last);
}
pt.clear_cnt();
for (int x : S)
pt.st[x].cnt += 1;
pt.dpcnt();
vector<int> cnt(pt.st.size());
for (size_t i = 0; i < pt.st.size(); i++) {
cnt[i] += pt.st[i].cnt;
}
pt.clear_cnt();
for (int x : F)
pt.st[x].cnt += 1;
pt.dpcnt();
for (size_t i = 0; i < pt.st.size(); i++) {
cnt[i] -= pt.st[i].cnt;
}
int ans = 0;
for (size_t i = 0; i < pt.st.size(); i++) {
int len = pt.st[i].len;
if (len <= n && len > 0) {
assert(cnt[i] >= 0 && cnt[i] <= n);
ans = add(ans, mul(mul(cnt[i], cnt[i]), len));
debug(cnt[i], len);
}
}
cout << ans << '\n';
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: 0
Accepted
time: 119ms
memory: 145408kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
496166704
result:
ok 1 number(s): "496166704"
Test #9:
score: 0
Accepted
time: 358ms
memory: 525700kb
input:
3000000 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...
output:
890701718
result:
ok 1 number(s): "890701718"
Test #10:
score: 0
Accepted
time: 268ms
memory: 287780kb
input:
3000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
224009870
result:
ok 1 number(s): "224009870"
Test #11:
score: 0
Accepted
time: 366ms
memory: 526208kb
input:
3000000 8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...
output:
51985943
result:
ok 1 number(s): "51985943"
Test #12:
score: 0
Accepted
time: 350ms
memory: 525748kb
input:
3000000 1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...
output:
355676465
result:
ok 1 number(s): "355676465"
Test #13:
score: 0
Accepted
time: 380ms
memory: 545048kb
input:
3000000 7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
output:
788510374
result:
ok 1 number(s): "788510374"
Test #14:
score: 0
Accepted
time: 380ms
memory: 544508kb
input:
3000000 5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
691884476
result:
ok 1 number(s): "691884476"
Test #15:
score: 0
Accepted
time: 258ms
memory: 268100kb
input:
3000000 0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...
output:
701050848
result:
ok 1 number(s): "701050848"
Test #16:
score: 0
Accepted
time: 110ms
memory: 132164kb
input:
3000000 2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...
output:
486861605
result:
ok 1 number(s): "486861605"
Test #17:
score: 0
Accepted
time: 339ms
memory: 546812kb
input:
3000000 4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...
output:
450625621
result:
ok 1 number(s): "450625621"
Test #18:
score: 0
Accepted
time: 362ms
memory: 546992kb
input:
3000000 1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...
output:
649551870
result:
ok 1 number(s): "649551870"
Extra Test:
score: 0
Extra Test Passed