/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 2ms 356.0 KiB
#3 Wrong Answer 4ms 328.0 KiB
#4 Wrong Answer 5ms 332.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll tc;
    cin>>tc;
    while(tc--)
    {
        ll n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        vector<pair<ll,ll>>u;
        for(int i=0;i<s.size()-2;i++)
        {
            string l;
            l="abc";
            ll cst=0;
            if(s[i]<=l[0])
             cst+=(l[0]-s[i]);
            else
                cst+=(('z'-s[i])+1+(l[0]-'a'));
             if(s[i+1]<=l[1])
             cst+=(l[1]-s[i+1]);
            else
                cst+=(('z'-s[i+1])+1+(l[1]-'a'));
              if(s[i+2]<=l[2])
             cst+=(l[2]-s[i+2]);
            else
                cst+=(('z'-s[i+2])+1+(l[2]-'a'));
            u.push_back({cst,i});
        }
        sort(u.begin(),u.end());
        ll ans=0;
    map<ll,ll>mp;
        for(int i=0;i<u.size();i++)
        {
            if(u[i].first<=k && mp[u[i].second]==0 && mp[u[i].second+1]==0 && mp[u[i].second+2]==0)
            {
                ans++;
                k-=u[i].first;
                mp[u[i].second]++;
                mp[u[i].second+1]++;
                mp[u[i].second+2]++;
            }
        }
        cout<<ans<<endl;
    }
    
}

Information

Submit By
Type
Submission
Problem
P1100 Substring ABC
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-05 08:22:37
Judged At
2024-11-11 02:40:17
Judged By
Score
9
Total Time
5ms
Peak Memory
540.0 KiB