/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 400.0 KiB
#3 Wrong Answer 4ms 532.0 KiB
#4 Wrong Answer 4ms 332.0 KiB
#5 Wrong Answer 14ms 320.0 KiB
#6 Wrong Answer 111ms 536.0 KiB
#7 Wrong Answer 324ms 568.0 KiB
#8 Wrong Answer 277ms 572.0 KiB
#9 Wrong Answer 761ms 572.0 KiB
#10 Time Exceeded ≥1000ms ≥568.0 KiB
#11 Time Exceeded ≥1001ms ≥576.0 KiB
#12 Time Exceeded ≥1000ms ≥572.0 KiB
#13 Time Exceeded ≥1100ms ≥576.0 KiB
#14 Time Exceeded ≥1100ms ≥572.0 KiB
#15 Time Exceeded ≥1000ms ≥572.0 KiB
#16 Time Exceeded ≥1001ms ≥572.0 KiB
#17 Time Exceeded ≥1000ms ≥672.0 KiB
#18 Wrong Answer 4ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define prime_number[21]={11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
///POLICY BASED DATA STRUCTURE..
///order_of_key return number of element which are strictly greater/smaller than x..
///find_by_order return ans iterator corresponding to the xth position of the set..
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define faster_bro ios_base::sync_with_stdio(false);cin.tie(NULL)
#define esp 0.0000000001
#define ss second
#define ff first
#define nl cout<<endl
//memset(ar,-1,sizeof(ar));
// (1LL<<i) more than efficient pow(2,i);
void fast(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    fast();
    int tc;
    cin>>tc;
    int h=1;
    while(tc--){
        ll a,b,c,sum=0,sum1=0,sum2=0,cnt=0,mx=LLONG_MIN,mn=LLONG_MAX,mx1=-1e18,mx2=-1e18;
        cin>>a>>b;
        string s;
        cin>>s;
        char c1='z';

      ll lagbe;
      set<int>st;
      int j=1;
      map<char,int>mp;
      for(char i='a';i<='z';i++){
           mp[i]=j;
           j++;
      }
      int l=mp['z'];
        for(int i=0;i<a-2;i++){
          // cout<<i<<" ";
                int f=0;
                int pos;
                mn=INT_MAX;
                if(st.find(i)!=st.end()){
                    continue;
                }
        if(s[i]=='a' && s[i+1]=='b' && s[i+2]=='c'){

            st.insert(i);
            st.insert(i+1);
            st.insert(i+2);
              i+=2;
            continue;
        }
            for(int j=0;j<a-2;j++){
                      if(st.find(j)!=st.end()){
                    continue;
                }
                int k1=mp[s[j]];
                int k11;
                if(s[j]=='a'){
                    k11=0;
                }
                else{
                    k11=(l-k1+1);
                }
                int k2=mp[s[j+1]];
                int k22;
                  if(s[j+1]=='b'){
                    k22=0;
                }
                else{
                        if(s[j+1]<'b'){

                            k22=mp['b'] - mp[s[j+1]];
                        }
                        else
                    k22=(l-k2+2);
                }
                int k3=mp[s[j+2]];
                int k33;
                  if(s[j+2]=='c'){
                    k33=0;
                }
                else{
                             if(s[j+2]<'c'){

                            k33=mp['c'] - mp[s[j+2]];
                        }
                        else
                    k33=(l-k3+3);
                }
           // cout<<k1<<" "<<k2<<" "<<k3<<endl;
                lagbe=k11 + k22 + k33;
                //cout<<lagbe<<" ";
                if(lagbe<=b){
                        f=1;
                    if(lagbe<mn){
                            mn=lagbe;
                        pos=j;
                    }
                }

            }
           // cout<<endl;
           //cout<<mn<<" "<<pos<<endl;

            if(f==1){
                    st.insert(pos);
                    st.insert(pos+1);
                    st.insert(pos+2);
                b-=mn;
                s[pos]='a';
                s[pos+1]='b';
                s[pos+2]='c';
            }

        }
         cnt=0;
        for(int i=0;i<a-2;i++){
             if(s[i]=='a' && s[i+1]=='b' && s[i+2]=='c'){
                 cnt++;
             i+=2;
             }

        }
        cout<<cnt<<endl;




        }

    }

Information

Submit By
Type
Submission
Problem
P1100 Substring ABC
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:35:07
Judged At
2024-10-03 17:35:07
Judged By
Score
2
Total Time
≥1100ms
Peak Memory
≥672.0 KiB