D. Good Triple
程序员文章站
2024-03-05 18:10:19
...
题解:
找到满足题意的区间,使满足l,r范围内有解
当同一范围内的区间存在覆盖的情况,取小的区间可以使解尽量多
所以暴力枚举可解
枚举左端点,依次累加右端点距n的距离即为所求解的情况
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int N=1e6+10;
const long long INF=1e18;
const double eps=0.0000001;
int a[N];
int n,m;
string s;
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>s;
int n=(int)s.length();
ll ans=0;
vector<int>cup(n+1,n);
for(int i=n-1;i>=0;i--)
{
cup[i]=cup[i+1];
for(int k=1;2*k+i<cup[i];k++)
//找到满足条件的区间尽量小,才可以使l,r尽量多
{
if(s[i]==s[i+2*k]&&s[i]==s[i+k])
cup[i]=i+2*k;
}
ans+=(n-cup[i]);
}
cout<<ans<<endl;
}
上一篇: Spark Transformation
推荐阅读
-
3DES(DESede、Triple-DES、DES-EDE) 加解密 JAVA
-
3DES(DESede、Triple-DES、DES-EDE) 加解密 C#
-
【扫描线+计数去重】Codeforces Round #672 (Div. 2) D. Rescue Nibel!
-
Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems 矩阵优化
-
Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair
-
【 Educational Codeforces Round 53 (Rated for Div. 2) D. Berland Fair】思维题
-
CFgym:Good morning!(dfs)
-
Different is Good
-
C. Good Subarraystime
-
D. Good Triple