ログインしてください。
提出 #51818042
ソースコード 拡げる
#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;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Substring |
| ユーザ | liruixuan |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 200 |
| コード長 | 711 Byte |
| 結果 | AC |
| 実行時間 | 1 ms |
| メモリ | 3852 KiB |
コンパイルエラー
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;
| ~~~~~^~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 200 / 200 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 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 |