Codeforces Round #833 (Div. 2)-B

B

题目链接:https://codeforces.com/contest/1748/problem/B

 What is the maximum possible length a diverse string?

100! 10个数字每个出现10次

暴力n*102

下见代码

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
//#define int long long

inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

using namespace std;
const int maxm=1e5+5,inf=0x3f3f3f3f;
int n;
string ss;

void solve(){
	cin>>n>>ss;
	int ans=0,maxlen,types;
	vector<int> cnt(100,0);
	for(int i=0;i<n;++i){
		maxlen=types=0;
		cnt.assign(100,0);
		for(int j=i;j<i+101&&j<n;++j){
			if(cnt[ss[j]]==0){
				++types;
			}
			++cnt[ss[j]];
			maxlen=max(maxlen,cnt[ss[j]]);
			if(types>=maxlen) ++ans;
		}
	}
	cout<<ans<<endl; 
	return ;
}

signed main(){
//	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int _=1;
	cin>>_;
	while(_--){
		solve();
	}
	return 0;
}

  

posted @ 2022-11-17 16:26  Qiansui  阅读(32)  评论(0)    收藏  举报