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
下见代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #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; } |
本文来自博客园,作者:Qiansui,转载请注明原文链接:https://www.cnblogs.com/Qiansui/p/16899884.html
分类:
oj - Codeforces
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】