Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33297 22级廖思学 【J】T4 C++ 通过 100 377 MS 2200 KB 959 2024-10-04 20:01:01

Tests(20/20):


#include<bits/stdc++.h> using namespace std; const int N=5e6+10; int ans=0; string s; //lst:上一个和上上个这个字符出现在哪里 struct Lst{int l,r;}t[30],txt[30]; bool cmp(Lst x,Lst y){ if(x.l!=y.l)return x.l<y.l; else return x.r<y.r; } signed main(){ // freopen("string.in","r",stdin); // freopen("20241004T4.out","w",stdout); cin>>s; // cout<<s<<endl; int n=s.length();s='0'+s; for(int i=1;i<=n;i++){ t[s[i]-'a'].l=t[s[i]-'a'].r; t[s[i]-'a'].r=i; // for(int j=0;j<2;j++)cout<<t[j].l<<" "<<t[j].r<<endl; for(int j=0;j<26;j++){txt[j]=t[j];} sort(txt,txt+26,cmp); int last=0; for(int j=0;j<26;j++){ // cout<<j<<" "<<txt[j].l<<" "<<txt[j].r<<" "<<last<<" "; if(txt[j].r<=last){continue;} if(txt[j].l<=last){ans+=txt[j].r-last;last=txt[j].r;} else{ans+=txt[j].r-txt[j].l;last=txt[j].r;} // cout<<ans<<endl; } // cout<<ans<<endl; // cout<<endl; } cout<<ans<<endl; return 0; }


测评信息: