/ SeriousOJ /

Record Detail

Compile Error

foo.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e6+10,MOD=1000000007;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
       string S;
       cin>>S;
       int n=S.size();
       map<char,int>mp;
       for(char ch:S)mp[ch]++;
       int ans=n;
       for(char ch='A';ch<='C';ch++){
           if(mp[ch]==0)continue;
           int l=mp[ch];
           if(l==n){
            ans=0;
            break;
           }
           string p=S;
           string cur="";
           int cnt=0;
           for(int i=0;i<l;i++){
             if(p[i]!=ch)cnt++,cur+=p[i];
           }
           sort(cur.begin(),cur.end());
           string temp="";
           int pos=0;
           for(int j=l;j<n;j++){
               if(p[j]==ch)temp+=cur[pos],pos++;
               else temp+=p[j];
           }
           int a=0;
           for(int j=0;j<mp[temp[0]];j++){
              if(temp[j]!=temp[0])a++;
           }
           ans=min(ans,cnt+a);
           reverse(cur.begin(),cur.end());
           temp="";
           pos=0;
           for(int j=l;j<n;j++){
               if(p[j]==ch)temp+=cur[pos],pos++;
               else temp+=p[j];
           }
            a=0;
           for(int j=0;j<mp[temp[0]];j++){
              if(temp[j]!=temp[0])a++;
           }
           ans=min(ans,cnt+a);
       }
       cout<<ans<<"\n";

    }
    
   
   return 0;
}
 

Information

Submit By
Type
Submission
Problem
P1059 String ABC
Language
C99 (GCC 13.2.0)
Submit At
2024-05-19 09:55:40
Judged At
2024-05-19 09:55:40
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes