/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 2ms 764.0 KiB
#5 Accepted 2ms 1.0 MiB
#6 Accepted 2ms 788.0 KiB
#7 Accepted 2ms 788.0 KiB
#8 Accepted 10ms 1.57 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-11-11 03:42:02
Judged By
Score
100
Total Time
10ms
Peak Memory
1.57 MiB