Submission #51818042
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
long long ans;
const int _=2e6;
int n,z[_],h[_],tot,a,t[_][26],f[_];
char s[_];
inline void add(int c){
int p=a,np=a=++tot,q,nq;
h[np]=h[p]+1;
for(;p&&!t[p][c];p=f[p])t[p][c]=np;
if(!p)f[np]=1;
else{
q=t[p][c];
if(h[q]==h[p]+1)f[np]=q;
else{
nq=++tot;h[nq]=h[p]+1;f[nq]=f[q];
memcpy(t[nq],t[q],sizeof(t[nq]));
f[np]=f[q]=nq;
for(;p&&t[p][c]==q;p=f[p])t[p][c]=nq;
}
}
}
int dfs(int x){
if(z[x])return z[x];
for(int i=0;i<26;i++)
if(t[x][i])z[x]+=dfs(t[x][i])+1;
return z[x];
}
int main(){
scanf("%s",s+1);n=strlen(s+1);tot=a=1;
for(int i=1;i<=n;i++)add(s[i]-'a');
printf("%d\n",dfs(1));
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Substring |
| User | liruixuan |
| Language | C++ 20 (gcc 12.2) |
| Score | 200 |
| Code Size | 711 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3852 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%s",s+1);n=strlen(s+1);tot=a=1;
| ~~~~~^~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 1 ms | 3600 KiB |
| 00_sample_02.txt | AC | 1 ms | 3836 KiB |
| 00_sample_03.txt | AC | 1 ms | 3640 KiB |
| 01_test_01.txt | AC | 1 ms | 3652 KiB |
| 01_test_02.txt | AC | 1 ms | 3800 KiB |
| 01_test_03.txt | AC | 1 ms | 3772 KiB |
| 01_test_04.txt | AC | 1 ms | 3644 KiB |
| 01_test_05.txt | AC | 1 ms | 3852 KiB |
| 01_test_06.txt | AC | 1 ms | 3660 KiB |
| 01_test_07.txt | AC | 1 ms | 3656 KiB |
| 01_test_08.txt | AC | 1 ms | 3720 KiB |
| 01_test_09.txt | AC | 1 ms | 3656 KiB |
| 01_test_10.txt | AC | 1 ms | 3720 KiB |