QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#272009#7876. Cyclic Substringsucup-team1321#AC ✓133ms338176kbC++202.0kb2023-12-02 15:39:082023-12-02 15:39:09

Judging History

你现在查看的是最新测评结果

  • [2023-12-02 15:39:09]
  • 评测
  • 测评结果:AC
  • 用时:133ms
  • 内存:338176kb
  • [2023-12-02 15:39:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 6000005;
const int P = 998244353;
int nn;
struct PAM {
  PAM() { init(); }
  int fail[N + 2];
  int len[N + 2];
  int cnt[N + 2];
  int num[N + 2];
  int s[N + 2];
  struct Edge {
    int v, nxt, w;
  } e[N + 2];
  int head[N + 2];
  int ec;
  void link(int u, int v, int w) {
    e[++ec] = {v, head[u], w};
    head[u] = ec;
  }
  int n, p, last;
  void init() {
    n = 0;
    p = 0;
    ec = 0;
    s[0] = -1;
    newnode(0);
    newnode(-1);
    last = 0;
    fail[0] = 1;
  }
  int newnode(int l) {
    head[p] = 0;
    cnt[p] = 0;
    num[p] = 0;
    len[p] = l;
    return p++;
  }
  int getfail(int x) {
    while (s[n - len[x] - 1] != s[n]) {
      x = fail[x];
    }
    return x;
  }
  int find(int cur, int c) {
    for (int i = head[cur]; i; i = e[i].nxt) {
      if (e[i].w == c) {
        return e[i].v;
      }
    }
    return 0;
  }
  void insert(int c) {
    s[++n] = c;
    int cur = getfail(last);
    if (!find(cur, c)) {
      int now = newnode(len[cur] + 2);
      fail[now] = find(getfail(fail[cur]), c);
      link(cur, now, c);
      num[now] = num[fail[now]] + 1;
    }
    last = find(cur, c);
    cnt[last]++;
  }
  void calc() {
    for (int i = p - 1; i >= 2; i--) cnt[fail[i]] += cnt[i];
  }
  
} pt, pt2;

int main() {
    cin >> nn; 
  string s;
  cin >> s;
  for (int i = 0; i < nn; i++) {
    int c = s[i] - 48;
    pt.insert(c);
  }
  
  for (int i = 0; i < nn; i++) {
      int c = s[i] - 48;
      pt2.insert(c);
  }
  for (int i = 0; i < nn; i++) {
      int c = s[i] - 48;
      pt2.insert(c);
  }
  pt.calc();
  pt2.calc();
  long long ans = 0;
    int p = pt2.p;
    for (int i = 2; i < p; i++){
        int cnt = pt2.cnt[i] - pt.cnt[i];
        int len = pt2.len[i];
        if (len <= nn) {
            ans += 1ll * cnt * cnt % P * len % P;
            if(ans >= P) ans -= P; 
        }
    }
  cout << ans << "\n";
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 30224kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 0ms
memory: 30224kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 0ms
memory: 30228kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 30100kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 0ms
memory: 30108kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 0ms
memory: 30236kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 0ms
memory: 30228kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 54ms
memory: 135948kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 128ms
memory: 335648kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 111ms
memory: 224044kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 133ms
memory: 337980kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 107ms
memory: 338176kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 115ms
memory: 306496kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 132ms
memory: 315404kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 91ms
memory: 257368kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 83ms
memory: 122416kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 104ms
memory: 291136kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 89ms
memory: 280288kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed