304172026-07-05 20:11:20KristófMagiccpp17Időlimit túllépés 30/1001.088s25140 KiB
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
string s;
int n;
int k;
vector<vector<int>> pref;

bool check(int l,int r)// if l to r is a good range
    {
    int st=0;
    for(int type=1;type<=k;type++)
        {
        if(l!=0)
            {
            if(type==1)st=pref[r][type]-pref[l-1][type];
            else if(st!=(pref[r][type]-pref[l-1][type]))return false;
            }
        else
            {
            if(type==1)st=pref[r][type];
            else if(st!=(pref[r][type]))return false;
            }
        }
    return true;
    }

int main()
{
    set<char> dif;
    cin>>n>>s;
    for(auto x:s)dif.insert(x);
    k=dif.size();
    map<char,int> conv;
    int id=1;
    vector<int> a;
    a.reserve(n);
    for(auto &x:s)
        {
        if(conv[x]==0)
            {
            conv[x]=id++;
            }
        a.push_back(conv[x]);
        }
    pref.resize(n,vector<int>(k+1,0));
    for(int i=0;i<n;i++)
        {
        for(int type=1;type<=k;type++)
            {
            if(i==0)break;
            pref[i][type]=pref[i-1][type];
            }
        pref[i][a[i]]++;
        }
    long long ans=0;

    for(int i=0;i<n;i++)
        for(int j=i;j<n;j++)
            ans+=check(i,j);
    //cout<<check(0,1)<<"\n";
    cout<<ans;
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask110/10
1Elfogadva1ms316 KiB
2Elfogadva1ms508 KiB
subtask220/20
1Elfogadva1ms316 KiB
2Elfogadva2ms316 KiB
3Elfogadva3ms316 KiB
4Elfogadva14ms900 KiB
5Elfogadva9ms316 KiB
subtask30/30
1Elfogadva54ms756 KiB
2Elfogadva861ms1588 KiB
3Időlimit túllépés1.077s3380 KiB
4Időlimit túllépés1.078s6196 KiB
5Időlimit túllépés1.088s6196 KiB
subtask40/40
1Időlimit túllépés1.088s6380 KiB
2Elfogadva354ms2868 KiB
3Időlimit túllépés1.088s3380 KiB
4Időlimit túllépés1.088s9268 KiB
5Időlimit túllépés1.08s25140 KiB
6Időlimit túllépés1.085s25132 KiB
7Időlimit túllépés1.083s11060 KiB
8Időlimit túllépés1.083s12596 KiB