Submission #74676078
Source Code Expand
// Problem: G - 221 Substring
// Contest: AtCoder - AtCoder Beginner Contest 452
// URL: https://atcoder.jp/contests/abc452/tasks/abc452_g
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#pragma GCC optimize("Ofast,inline,unroll-loops")
#ifdef GTRAKIOI
#define _GLIBCXX_DEBUG //交题前记得注释掉不然容易T。
#endif
#include<bits/stdc++.h>
// #include<stdio.h>
#define File(s) freopen(#s".in","r",stdin),freopen(#s".out","w",stdout)
#ifdef GTRAKIOI
#include"C:/code/deb_20.cpp"
#define defrog(...) fprintf(stderr,__VA_ARGS__)
#define deb(x) (std::cerr<<#x<<"@"<<__LINE__<<"="<<(x)<<'\n')
#else
#define defrog(...) 1
#define deb(x) 1
#define debug(...) 1
#define debugArr(...) 1
#endif
#define defrogf(...) defrog(__VA_ARGS__)
#define Tp template<typename T>
#define Tl template<typename T
#define Tr >
#define IS(cond) ,std::enable_if_t<(cond), int> = 0
#if __cplusplus>=201703L
#define register
#endif
#ifdef _MSC_VER
#if __has_include(<__msvc_int128.hpp>)
#include <__msvc_int128.hpp> // https://stackoverflow.com/a/76440171
#define __int128 std::_Signed128
#define __int128_t std::_Signed128
#define __uint128_t std::_Unsigned128
#define __SIZEOF_INT128__ 16
#endif
#endif
using ll=long long;
// #define int ll
using ull=unsigned long long;
#ifdef __SIZEOF_INT128__
using lll=__int128;
// using ulll=unsigned __int128;
#endif
using db=double;
using ld=long double;
#define INT_ALIAS(w) using i##w=std::int##w##_t;using u##w=std::uint##w##_t;
INT_ALIAS(8) INT_ALIAS(16) INT_ALIAS(32) INT_ALIAS(64)
#ifdef __SIZEOF_INT128__
using i128=__int128_t;
using u128=__uint128_t;
using i7=__int128_t;
using u7=__uint128_t;
template <class T>
using to_unsigned = typename std::conditional<
std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::common_type<__uint128_t>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T>
using to_unsigned = std::make_unsigned<T>;
#endif
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
template<typename T>using vv=std::vector<T>;
template<typename T>using V=std::vector<T>;
using pii=std::pair<int,int>;
using vi=V<int>;
using vll=V<ll>;
using vpii=V<pii>;
using vvi=V<vi>;
template<typename T>using pq=std::priority_queue<T>;
template<typename T>using pqg=std::priority_queue<T,std::vector<T>,std::greater<>>;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define all(cont) std::begin(cont),std::end(cont)
#define rall(cont) std::rbegin(cont),std::rend(cont)
#define G90 1
#ifdef G90
char ibuf[1<<15],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
#endif
struct FastIO{
Tl IS(!std::numeric_limits<T>::is_signed) Tr inline void oint(T x){
T y=1;
while(y<=x/10)y*=10;
do putchar(int(x/y)|48),x%=y,y/=10;while(y);
}
Tl IS(std::numeric_limits<T>::is_signed) Tr inline void oint(const T&x){
if(x<0){
putchar('-');
oint<to_unsigned_t<T>>(-x);
}else oint<to_unsigned_t<T>>(x);
}
#ifdef G90
Tl=int IS(std::numeric_limits<T>::is_integer) Tr inline T rint(){register char c,f=0;while((c=getchar())<48||c>57)f|=c=='-';to_unsigned_t<T> a=c&15;while((c=getchar())>=48&&c<=57)a=a*10+(c&15);return f?~a+1:a;}
// inline ll rll(){rg char c,f=0;while((c=getchar())<48||c>57)f|=c=='-';rg ull a=c&15;while((c=getchar())>=48&&c<=57)a=a*10+(c&15);return f?~a+1:a;}
// inline operator int(){return rint();}
// inline operator ll(){return rll();}
Tl IS(std::numeric_limits<T>::is_integer) Tr inline operator T(){return rint<T>();}
inline char rchar(){register char c;while(!isgraph(c=getchar()));return c;}
inline int rstr(char*s){register char c;while(!isgraph(c=getchar()));int cnt=-1;do s[++cnt]=c;while(isgraph(c=getchar()));s[++cnt]=0;return cnt;}
inline std::string rs(){register char c;while(!isgraph(c=getchar()));std::string s;do s+=c;while(isgraph(c=getchar()));return s;}
#else
Tp requires requires(std::istream&is,T&x){is>>x;} inline operator T(){T a;std::cin>>a;return a;}
inline char rchar(){return char(*this);}
inline int rstr(char*s){register char c=-1;while(!isgraph(c=char(std::cin.get())));int cnt=-1;do s[++cnt]=c;while(isgraph(c=char(std::cin.get())));s[++cnt]=0;return cnt;}
inline std::string rs(){return *this;}
#endif
Tl IS(std::numeric_limits<T>::is_integer) Tr inline void print(const T&x){oint(x);}
inline void print(const char&x){putchar(x);}
inline void print(const char*const&x){for(int i=0;x[i];++i)putchar(x[i]);}
#if __cplusplus >= 202002L
Tp requires std::ranges::range<T> inline void print(const T&c){
bool first=true;
for(const auto&x:c){
if(!first)putchar(' ');
first=false;
print(x);
}
}
#endif
inline void print(const std::string&x){for(int i=0;x[i];++i)putchar(x[i]);}
// print with separators
// inline void prints(){putchar('\n');}
// inline void prints(const auto&x,const auto&...rst){print(x),putchar(' '),prints(rst...);}
inline void prints(const auto&...x){((print(x),putchar(' ')),...);putchar('\n');}
}g90;
inline void YON(const bool&x){puts(x?"YES":"NO");}
inline void Yon(const bool&x){puts(x?"Yes":"No");}
inline void yon(const bool&x){puts(x?"yes":"no");}
template<typename T=int>std::vector<T>rvec(std::size_t n,std::size_t start=0) {
std::vector<T>res(start+n);
for(std::size_t i=start;i<start+n;++i)res[i]=g90;
return res;
}
std::mt19937_64 rng(u32(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
Tl IS(std::is_floating_point<T>::value) Tr inline T rnd(const T&a,const T&b){
return std::uniform_real_distribution<T>(a,b)(rng);
}
Tl IS(std::numeric_limits<T>::is_integer) Tr inline T rnd(const T&a,const T&b){
return std::uniform_int_distribution<T>(a,b)(rng);
}
namespace MY_STD{
Tp inline T abs(const T&a){return a<0?-a:a;}
}
#if __cplusplus >= 202002L
namespace all{
using namespace std::ranges;
using namespace std::views;
//ambiguous ones
using std::views::iota;
using std::views::empty;
using std::views::reverse;
inline constexpr auto&R=std::views::reverse;
}
#else
#define ssize(a) int((a).size())
#endif
struct DSU{//unweighted
using key_type=int;
std::vector<key_type>fa,size;
inline DSU(key_type n):fa(n),size(n,1){std::iota(fa.begin(),fa.end(),0);}
inline key_type& getFa(key_type x){
while(x^fa[x])x=fa[x]=fa[fa[x]];
return fa[x];
}
inline key_type& operator[](const key_type&x){return getFa(x);}
inline auto canMerge(const key_type&u,const key_type&v){return getFa(u)!=getFa(v);}
inline bool merge(key_type u,key_type v){
u=getFa(u),v=getFa(v);
return (u)!=(v)&&(size[u]<size[v]&&(std::swap(u,v),1),fa[v]=u,size[u]+=size[v],size[v]=0,true);
}
};
template<typename Compare=std::less<>>inline bool ckmax(auto& a,const auto& b,const Compare&comp={}){return comp(a,b)?(a=b,true):false;}
template<typename Compare=std::less<>>inline bool ckmin(auto& a,const auto& b,const Compare&comp={}){return comp(b,a)?(a=b,true):false;}
inline auto divf(const auto&a,const auto&b){//assume b>0
return a<0?(a+1)/b-1:a/b;
}
inline auto divc(const auto&a,const auto&b){//assume b>0
return a>0?(a-1)/b+1:a/b;
}
#define fi first
#define se second
// #define x first
// #define y second
constexpr int N=2333333,M=11;//1000000007;
constexpr int MAXN=N,MAXM=M;
// using mint = atcoder::static_modint<M>;
inline int qpow(ll a,auto b){int res=1;for(;b;a=a*a%M,b>>=1)if(b&1)res=res*a%M;return res;}
// #define pow qpow
int n=g90;
vi a=rvec(n);
namespace SAM{//https://hourai.nanani-fan.club/sam/
int M[MAXN][MAXM], L[MAXN], F[MAXN], S[MAXN], last = 0, s = 0, h = 9;
void init(){
F[0] = -1, last = s = 0;
}
void extend(char c){
int cur = ++ s, e = c;
L[cur] = L[last] + 1, S[cur] = 1;
int p = last;
while(p != -1 && !M[p][e])
M[p][e] = cur, p = F[p];
if(p == -1){
F[cur] = 0;
} else {
int q = M[p][e];
if(L[p] + 1 == L[q]){
F[cur] = q;
} else {
int clone = ++ s;
L[clone] = L[p] + 1, F[clone] = F[q];
S[clone] = 0;
for(int i = 0;i <= h;++ i)
M[clone][i] = M[q][i];
while(p != -1 && M[p][e] == q)
M[p][e] = clone, p = F[p];
F[cur] = F[q] = clone;
}
}
last = cur;
}
void solve(){
init();
for(auto&x:a)extend(x);
vvi occ(n+1);
for(int i=0;i<=s;++i){
occ[L[i]].eb(i);
}
V f(s+1,vll(10));
ll ans=0;
for(int l=n;~l;--l)for(auto&u:occ[l]){
for(int tns=1;tns<=9;++tns){
int _=0,v=u;
for(;_<tns;++_){
v=M[v][tns];
if(!v)break;
}
if(_==tns){
debug(u,tns,v);
ll x=f[v][0]-f[v][tns]+1;
f[u][0]+=x,f[u][tns]+=x;
}
}
}
printf("%lld\n",f[0][0]);
}
}
signed main(){
using std::cin,std::cout,std::cerr;
//std::ios::sync_with_stdio(0);std::cin.tie(0);std::cout.tie(0);
SAM::solve();
}//main()
Submission Info
| Submission Time |
|
| Task |
G - 221 Substring |
| User |
fission |
| Language |
C++23 (GCC 15.2.0) |
| Score |
600 |
| Code Size |
9227 Byte |
| Status |
AC |
| Exec Time |
202 ms |
| Memory |
203684 KiB |
Compile Error
./Main.cpp: In function 'void SAM::solve()':
./Main.cpp:23:20: warning: statement has no effect [-Wunused-value]
23 | #define debug(...) 1
| ^
./Main.cpp:262:33: note: in expansion of macro 'debug'
262 | debug(u,tns,v);
| ^~~~~
./Main.cpp:253:12: warning: unused variable 'ans' [-Wunused-variable]
253 | ll ans=0;
| ^~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-01.txt, 00-sample-02.txt |
| All |
00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-01.txt |
AC |
1 ms |
3724 KiB |
| 00-sample-02.txt |
AC |
1 ms |
3876 KiB |
| 01-01.txt |
AC |
1 ms |
3920 KiB |
| 01-02.txt |
AC |
1 ms |
3892 KiB |
| 01-03.txt |
AC |
1 ms |
3856 KiB |
| 01-04.txt |
AC |
1 ms |
3848 KiB |
| 01-05.txt |
AC |
1 ms |
4004 KiB |
| 01-06.txt |
AC |
1 ms |
3796 KiB |
| 01-07.txt |
AC |
1 ms |
3808 KiB |
| 01-08.txt |
AC |
1 ms |
3824 KiB |
| 01-09.txt |
AC |
1 ms |
3796 KiB |
| 01-10.txt |
AC |
1 ms |
3768 KiB |
| 01-11.txt |
AC |
1 ms |
3836 KiB |
| 01-12.txt |
AC |
1 ms |
3796 KiB |
| 01-13.txt |
AC |
1 ms |
3768 KiB |
| 01-14.txt |
AC |
1 ms |
3920 KiB |
| 01-15.txt |
AC |
1 ms |
3920 KiB |
| 01-16.txt |
AC |
1 ms |
3836 KiB |
| 01-17.txt |
AC |
1 ms |
3768 KiB |
| 01-18.txt |
AC |
1 ms |
3796 KiB |
| 01-19.txt |
AC |
1 ms |
3768 KiB |
| 01-20.txt |
AC |
159 ms |
152780 KiB |
| 01-21.txt |
AC |
98 ms |
128252 KiB |
| 01-22.txt |
AC |
79 ms |
116812 KiB |
| 01-23.txt |
AC |
82 ms |
116912 KiB |
| 01-24.txt |
AC |
195 ms |
202828 KiB |
| 01-25.txt |
AC |
129 ms |
148024 KiB |
| 01-26.txt |
AC |
159 ms |
156452 KiB |
| 01-27.txt |
AC |
120 ms |
165040 KiB |
| 01-28.txt |
AC |
128 ms |
175264 KiB |
| 01-29.txt |
AC |
142 ms |
193464 KiB |
| 01-30.txt |
AC |
183 ms |
203684 KiB |
| 01-31.txt |
AC |
197 ms |
202828 KiB |
| 01-32.txt |
AC |
201 ms |
202840 KiB |
| 01-33.txt |
AC |
202 ms |
202712 KiB |
| 01-34.txt |
AC |
199 ms |
195444 KiB |
| 01-35.txt |
AC |
173 ms |
193072 KiB |
| 01-36.txt |
AC |
173 ms |
192116 KiB |
| 01-37.txt |
AC |
173 ms |
192796 KiB |
| 01-38.txt |
AC |
181 ms |
185548 KiB |
| 01-39.txt |
AC |
159 ms |
156408 KiB |
| 01-40.txt |
AC |
157 ms |
156416 KiB |
| 01-41.txt |
AC |
157 ms |
156464 KiB |
| 01-42.txt |
AC |
159 ms |
156984 KiB |
| 01-43.txt |
AC |
1 ms |
3768 KiB |
| 01-44.txt |
AC |
1 ms |
3728 KiB |
| 01-45.txt |
AC |
1 ms |
3848 KiB |
| 01-46.txt |
AC |
2 ms |
5236 KiB |
| 01-47.txt |
AC |
2 ms |
5204 KiB |
| 01-48.txt |
AC |
2 ms |
5168 KiB |
| 01-49.txt |
AC |
178 ms |
161400 KiB |
| 01-50.txt |
AC |
167 ms |
159160 KiB |
| 01-51.txt |
AC |
179 ms |
162276 KiB |