QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#237017#7512. Almost Prefix ConcatenationDawn_SdyCompile Error//C++142.8kb2023-11-04 12:28:132023-11-04 12:28:13

Judging History

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

  • [2023-11-04 12:28:13]
  • 评测
  • [2023-11-04 12:28:13]
  • 提交

answer

#include<iostream>
#include<algorithm>

using namespace std;

const long long mod = 998244353;

int n, la, lb;
int len[2000010], rk[2000010], cnt[2000010], q[2000010], SA[2000010], k[2000010];
int st[2000010][25], h[2000010], ht[2000010], lg[2000010];
long long f[2000010][3], sum[2000010][3];
char s[2000010], t[2000010];

int LCP(int x, int y){
  if(x > y) swap(x, y);
  if(x == 0) return 0;
  return min(st[x][lg[y - x]], st[y - (1 << lg[y - x])][lg[y - x]]);
}
int main(){
/*    char c = getchar();
    while(!isalpha(c)) c = getchar();
    while(isalpha(c)) s += c, c = getchar();
    while(!isalpha(c) c = getchar();
    while(isalpha(c))) t += c, c = getchar();*/
    scanf("%s%s", s + 1, t + 1);
    la = strlen(s + 1), lb = strlen(t + 1);
    int n = la;
    s[++n] = '0';
    for(register int i = 1; i <= lb; ++i) s[++n] = t[i]; 
  for(int i = 1; i <= n; i++) cnt[s[i]]++;
  for(int i = 1; i <= 256; i++) cnt[i] += cnt[i - 1];
  for(int i = 1; i <= n; i++) rk[i] = cnt[s[i] - 1] + 1;
  for(int i = 1; i <= n; i++) SA[cnt[s[i]]--] = i;
    for(int i = 0; n >> i; i++){
        int T = (1 << i), t = 0, mx = rk[SA[n]];
        for(int j = n; j > n - T; j--) q[++t] = j;
        for(int j = 1; j <= n; j++){
            if(SA[j] > T) q[++t] = SA[j] - T;
            cnt[j] = 0;
        }
        for(int j = 1; j <= n; j++) cnt[rk[j]]++;
        for(int j = 1; j <= mx; j++) cnt[j] += cnt[j - 1];
        for(int j = n; j; j--) SA[cnt[rk[q[j]]]--] = q[j];
        for(int i = 1; i <= n; i++){
            k[SA[i]] = !(rk[SA[i] + T] == rk[SA[i - 1] + T] && rk[SA[i]] == rk[SA[i - 1]]) + k[SA[i - 1]];
        }
        copy(k + 1, k + n + 1, rk + 1);
    }
  for(int i = 1; i <= n; i++){
    if(i > 1) lg[i] = lg[i >> 1] + 1;
    if(rk[i] == 1) continue;
    ht[rk[i]] = max(0, ht[rk[i - 1]] - 1);
    while(SA[rk[i] - 1] + ht[rk[i]] <= n && s[i + ht[rk[i]]] == s[SA[rk[i] - 1]+ ht[rk[i]]]) ht[rk[i]]++;
    st[rk[i] - 1][0] = ht[rk[i]];
  }
  for(int i = 1; (1 << i) < n; i++){
    int T = (1 << i);
    for(int j = 1; j + T <= n; j++){
      st[j][i] = min(st[j][i - 1], st[j + (T >> 1)][i - 1]);
    }
  }
  for(int i = 1; i <= la; i++){
    len[i] = LCP(rk[i], rk[la + 2]);
    if(len[i] < min(la - i + 1, lb)) len[i] += LCP(rk[i + len[i] + 1], rk[la + len[i] + 3]) + 1;
  }
  f[la + 1][0] = sum[la + 1][0] = 1;
  for(int i = la; i; i--){
    int r = i + len[i];
    f[i][2] = ((sum[i + 1][2] - sum[r + 1][2] + 2 * (sum[i + 1][1] - sum[r + 1][1]) + sum[i + 1][0] - sum[r + 1][0]) % mod + mod) % mod;
    f[i][1] = (sum[i + 1][1] - sum[r + 1][1] + sum[i + 1][0] - sum[r + 1][0] + mod * 2) % mod;
    f[i][0] = (sum[i + 1][0] - sum[r + 1][0] + mod) % mod;
    for(int j = 0; j < 3; j++) sum[i][j] = (sum[i + 1][j] + f[i][j]) % mod;
  }
  cout << f[1][2];
  return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:26:10: error: ‘strlen’ was not declared in this scope
   26 |     la = strlen(s + 1), lb = strlen(t + 1);
      |          ^~~~~~
answer.code:3:1: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    2 | #include<algorithm>
  +++ |+#include <cstring>
    3 | 
answer.code:25:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |     scanf("%s%s", s + 1, t + 1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~