QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291420 | #7876. Cyclic Substrings | mendicillin2 | AC ✓ | 164ms | 395740kb | C++17 | 2.0kb | 2023-12-26 15:40:10 | 2023-12-26 15:40:11 |
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 { /// start-hash
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();
} /// end-hash
int dist(int v) { /// start-hash
return n[v].suf <= 0 ? -1 : n[v].len() - n[n[v].suf].len();
} /// end-hash
template <class A> int extend(A a) { /// start-hash
int i = sz(s);
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]] = sz(n);
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]];
} /// end-hash
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: 0ms
memory: 3824kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: 0
Accepted
time: 43ms
memory: 133428kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
496166704
result:
ok 1 number(s): "496166704"
Test #9:
score: 0
Accepted
time: 133ms
memory: 394908kb
input:
3000000 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...
output:
890701718
result:
ok 1 number(s): "890701718"
Test #10:
score: 0
Accepted
time: 116ms
memory: 200980kb
input:
3000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
224009870
result:
ok 1 number(s): "224009870"
Test #11:
score: 0
Accepted
time: 99ms
memory: 395740kb
input:
3000000 8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...
output:
51985943
result:
ok 1 number(s): "51985943"
Test #12:
score: 0
Accepted
time: 132ms
memory: 395624kb
input:
3000000 1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...
output:
355676465
result:
ok 1 number(s): "355676465"
Test #13:
score: 0
Accepted
time: 160ms
memory: 352444kb
input:
3000000 7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
output:
788510374
result:
ok 1 number(s): "788510374"
Test #14:
score: 0
Accepted
time: 164ms
memory: 364068kb
input:
3000000 5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
691884476
result:
ok 1 number(s): "691884476"
Test #15:
score: 0
Accepted
time: 82ms
memory: 217148kb
input:
3000000 0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...
output:
701050848
result:
ok 1 number(s): "701050848"
Test #16:
score: 0
Accepted
time: 63ms
memory: 105356kb
input:
3000000 2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...
output:
486861605
result:
ok 1 number(s): "486861605"
Test #17:
score: 0
Accepted
time: 117ms
memory: 339800kb
input:
3000000 4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...
output:
450625621
result:
ok 1 number(s): "450625621"
Test #18:
score: 0
Accepted
time: 102ms
memory: 332464kb
input:
3000000 1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...
output:
649551870
result:
ok 1 number(s): "649551870"
Extra Test:
score: 0
Extra Test Passed