Submission #74655822
Source Code Expand
// Problem: D - No-Subsequence Substring
// Contest: AtCoder - AtCoder Beginner Contest 452
// URL: https://atcoder.jp/contests/abc452/tasks/abc452_d
// 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=-2026,M=1;//1000000007;
// 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
signed main(){
using std::cin,std::cout,std::cerr;
//std::ios::sync_with_stdio(0);std::cin.tie(0);std::cout.tie(0);
auto s='a'+g90.rs();
auto t=g90.rs();
int n=ssize(s);
vvi nxt(n+1);
vi cnxt(27,n);
for(int i=n;~i;--i){
nxt[i]=cnxt;
if(i<n)cnxt[s[i]&31]=i;
}
ll ans=0;
for(int l=0;l<n;++l){
int r=l;
for(auto&x:t)r=nxt[r][x&31];
ans+=n-r;
}
printf("%lld\n",n*ll(n-1)/2-ans);
}//main()
Submission Info
| Submission Time |
|
| Task |
D - No-Subsequence Substring |
| User |
fission |
| Language |
C++23 (GCC 15.2.0) |
| Score |
400 |
| Code Size |
8155 Byte |
| Status |
AC |
| Exec Time |
41 ms |
| Memory |
33580 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3784 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3732 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3788 KiB |
| 01_random_03.txt |
AC |
18 ms |
21972 KiB |
| 01_random_04.txt |
AC |
24 ms |
23080 KiB |
| 01_random_05.txt |
AC |
9 ms |
14164 KiB |
| 01_random_06.txt |
AC |
12 ms |
13512 KiB |
| 01_random_07.txt |
AC |
13 ms |
18960 KiB |
| 01_random_08.txt |
AC |
24 ms |
33428 KiB |
| 01_random_09.txt |
AC |
33 ms |
33448 KiB |
| 01_random_10.txt |
AC |
26 ms |
33352 KiB |
| 01_random_11.txt |
AC |
35 ms |
33408 KiB |
| 01_random_12.txt |
AC |
18 ms |
33448 KiB |
| 01_random_13.txt |
AC |
18 ms |
33348 KiB |
| 01_random_14.txt |
AC |
26 ms |
33364 KiB |
| 01_random_15.txt |
AC |
31 ms |
33540 KiB |
| 01_random_16.txt |
AC |
37 ms |
33484 KiB |
| 01_random_17.txt |
AC |
24 ms |
33348 KiB |
| 01_random_18.txt |
AC |
17 ms |
33380 KiB |
| 01_random_19.txt |
AC |
38 ms |
33448 KiB |
| 01_random_20.txt |
AC |
25 ms |
33540 KiB |
| 01_random_21.txt |
AC |
19 ms |
33348 KiB |
| 01_random_22.txt |
AC |
34 ms |
33484 KiB |
| 01_random_23.txt |
AC |
35 ms |
33428 KiB |
| 01_random_24.txt |
AC |
32 ms |
33372 KiB |
| 01_random_25.txt |
AC |
41 ms |
33448 KiB |
| 01_random_26.txt |
AC |
23 ms |
33408 KiB |
| 01_random_27.txt |
AC |
26 ms |
33580 KiB |
| 01_random_28.txt |
AC |
34 ms |
33476 KiB |
| 01_random_29.txt |
AC |
26 ms |
33424 KiB |
| 01_random_30.txt |
AC |
23 ms |
33516 KiB |
| 01_random_31.txt |
AC |
22 ms |
33364 KiB |
| 01_random_32.txt |
AC |
16 ms |
33396 KiB |
| 01_random_33.txt |
AC |
32 ms |
33372 KiB |
| 01_random_34.txt |
AC |
27 ms |
33364 KiB |
| 01_random_35.txt |
AC |
36 ms |
33396 KiB |
| 01_random_36.txt |
AC |
31 ms |
33372 KiB |
| 01_random_37.txt |
AC |
23 ms |
33540 KiB |
| 01_random_38.txt |
AC |
22 ms |
33448 KiB |
| 01_random_39.txt |
AC |
22 ms |
33484 KiB |
| 01_random_40.txt |
AC |
18 ms |
30276 KiB |
| 01_random_41.txt |
AC |
25 ms |
27340 KiB |
| 01_random_42.txt |
AC |
24 ms |
29128 KiB |
| 01_random_43.txt |
AC |
7 ms |
12680 KiB |
| 01_random_44.txt |
AC |
18 ms |
25388 KiB |
| 01_random_45.txt |
AC |
6 ms |
9000 KiB |
| 01_random_46.txt |
AC |
26 ms |
29128 KiB |
| 01_random_47.txt |
AC |
16 ms |
17556 KiB |
| 01_random_48.txt |
AC |
5 ms |
12876 KiB |
| 01_random_49.txt |
AC |
19 ms |
23112 KiB |
| 01_random_50.txt |
AC |
14 ms |
28124 KiB |
| 01_random_51.txt |
AC |
34 ms |
33580 KiB |
| 01_random_52.txt |
AC |
15 ms |
33352 KiB |
| 01_random_53.txt |
AC |
1 ms |
3648 KiB |
| 01_random_54.txt |
AC |
1 ms |
3684 KiB |
| 01_random_55.txt |
AC |
1 ms |
3724 KiB |