QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291417 | #7876. Cyclic Substrings | mendicillin2 | AC ✓ | 164ms | 395880kb | C++17 | 2.0kb | 2023-12-26 15:35:29 | 2023-12-26 15:35:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <class T> int sz(T&& a) { return int(size(forward<T>(a))); }
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vector<T>>;
using ll = int64_t;
template <int K, class S> struct eertree {
struct N {
int suf, anc, l, r;
array<int, K> ch;
int len() const { return r-l; }
};
vc<N> n;
int c;
S s;
eertree(int alloc = 0) {
if (alloc > 2) n.reserve(alloc);
n.push_back({-1, -1, 1, 0, {}});
n.push_back({0, -1, 0, 0, {}});
reset();
}
void reset() {
c = 1;
s.clear();
}
int dist(int v) {
return n[v].suf <= 0 ? -1 : n[v].len() - n[n[v].suf].len();
}
template <class A> int extend(A a) {
int i = int(s.size());
s.push_back(a);
auto works = [&](int v) -> bool {
int l = i - n[v].len();
return l > 0 && s[l-1] == s[i];
};
while (!works(c)) c = n[c].suf;
if (!n[c].ch[s[i]]) {
int d = n[c].suf;
if (d != -1) while (!works(d)) d = n[d].suf;
int e = (d == -1 ? 1 : n[d].ch[s[i]]);
int f = n[c].ch[s[i]] = int(n.size());
n.push_back({e, e, i - n[c].len() - 1, i + 1, {}});
if (dist(e) == dist(f)) n[f].anc = n[e].anc;
}
return c = n[c].ch[s[i]];
}
const N& operator [] (int i) const {
return n[i];
}
};
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int N;
cin >> N;
string S;
cin >> S;
eertree<10, vc<int>> et(2*N+10);
for (int i = 0; i < N; i++) {
int a = int(S[i] - '0');
et.extend(a);
}
vc<int> locs(N);
for (int i = 0; i < N; i++) {
int a = int(S[i] - '0');
locs[i] = et.extend(a);
}
int num_et = int(et.n.size());
vc<int> dp(num_et);
for (int v : locs) {
dp[v]++;
}
constexpr int MOD = 998244353;
auto add = [&](int& a, int b) -> void {
a += b;
if (a >= MOD) a -= MOD;
};
int ans = 0;
for (int v = num_et-1; v >= 2; v--) {
add(dp[et[v].suf], dp[v]);
int len = et[v].len();
if (len <= N) {
int cur = int(ll(dp[v]) * dp[v] % MOD * len % MOD);
add(ans, cur);
}
}
cout << ans << '\n';
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3440kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3436kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: 0
Accepted
time: 31ms
memory: 133400kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
496166704
result:
ok 1 number(s): "496166704"
Test #9:
score: 0
Accepted
time: 120ms
memory: 395544kb
input:
3000000 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...
output:
890701718
result:
ok 1 number(s): "890701718"
Test #10:
score: 0
Accepted
time: 126ms
memory: 200892kb
input:
3000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
224009870
result:
ok 1 number(s): "224009870"
Test #11:
score: 0
Accepted
time: 115ms
memory: 395472kb
input:
3000000 8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...
output:
51985943
result:
ok 1 number(s): "51985943"
Test #12:
score: 0
Accepted
time: 103ms
memory: 395880kb
input:
3000000 1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...
output:
355676465
result:
ok 1 number(s): "355676465"
Test #13:
score: 0
Accepted
time: 164ms
memory: 351792kb
input:
3000000 7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
output:
788510374
result:
ok 1 number(s): "788510374"
Test #14:
score: 0
Accepted
time: 140ms
memory: 363956kb
input:
3000000 5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
691884476
result:
ok 1 number(s): "691884476"
Test #15:
score: 0
Accepted
time: 88ms
memory: 217248kb
input:
3000000 0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...
output:
701050848
result:
ok 1 number(s): "701050848"
Test #16:
score: 0
Accepted
time: 72ms
memory: 102648kb
input:
3000000 2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...
output:
486861605
result:
ok 1 number(s): "486861605"
Test #17:
score: 0
Accepted
time: 104ms
memory: 339668kb
input:
3000000 4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...
output:
450625621
result:
ok 1 number(s): "450625621"
Test #18:
score: 0
Accepted
time: 106ms
memory: 332412kb
input:
3000000 1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...
output:
649551870
result:
ok 1 number(s): "649551870"
Extra Test:
score: 0
Extra Test Passed