/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 1ms 2.527 MiB
#5 Accepted 1ms 668.0 KiB
#6 Accepted 1ms 2.527 MiB
#7 Accepted 1ms 668.0 KiB
#8 Accepted 9ms 1.527 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=1000000007;
typedef long long ll;
int fre[26][M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
    
        int n;
        cin>>n;
        string s;
        cin>>s;
        for(char ch='a';ch<='z';ch++){
            for(int i=1;i<=n;i++){
                fre[ch-'a'][i]=fre[ch-'a'][i-1]+(ch==s[i-1]);
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++){
              int l=s[i-1]-'a';
              int ok=0;
              for(int j=0;j<=25;j++){
                 if(l==j)continue;
                 int front=fre[j][i-1];
                 int back=fre[j][n]-fre[j][i];
                 if(front==back && front>0)ok=1;
              }
              ans+=ok;
        }
        cout<<ans<<"\n";
        for(char ch='a';ch<='z';ch++){
            for(int i=1;i<=n;i++)fre[ch-'a'][i]=0;
        }

    
   }
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1021 Pivot points
Contest
Brain booster #2
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-06 14:17:33
Judged At
2024-03-06 14:17:33
Judged By
Score
100
Total Time
9ms
Peak Memory
2.527 MiB