/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 764.0 KiB
#2 Accepted 178ms 568.0 KiB
#3 Accepted 275ms 572.0 KiB
#4 Accepted 289ms 708.0 KiB
#5 Accepted 575ms 1.863 MiB
#6 Accepted 855ms 13.637 MiB
#7 Accepted 840ms 13.637 MiB
#8 Accepted 782ms 13.641 MiB
#9 Accepted 785ms 13.645 MiB
#10 Accepted 704ms 13.641 MiB
#11 Accepted 728ms 13.637 MiB
#12 Accepted 732ms 13.641 MiB
#13 Accepted 729ms 13.641 MiB
#14 Accepted 711ms 13.637 MiB
#15 Accepted 706ms 13.539 MiB
#16 Accepted 759ms 13.637 MiB
#17 Accepted 750ms 13.645 MiB
#18 Accepted 684ms 13.637 MiB
#19 Accepted 678ms 13.637 MiB
#20 Accepted 719ms 13.641 MiB

Code

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
     int n,k;
     cin>>n>>k;
     string s;
     cin>>s;
     int res=0;
     for(char ch='a';ch<='z';ch++){
        string p="";
        char c=ch;
        int tt=26;
        while(tt>0){
            p+=c;
            if(c=='z')c='a';
            else c++;
            tt--;
        }
        int l=0;
        vector<vector<int>>dp(n+1,vector<int>(26,0));
        for(int i=0;i<n;i++){
            int j=i;
            int r=0;
            int cnt=0;
            while(j<n&& r<p.size()){
                cnt+=(s[j]!=p[r]);
                dp[i][r]=cnt;
                j++,r++;
            }
            while(r<26)dp[i][r]=cnt,r++;
            //dp[i]=cnt;
        }
        for(int j=0;j<min(26,n);j++){
          int l=j;
          int r=j;
          int cur=0;
          int limit=26;
          tt=k;
          while(r<n){
                int temp=0;
                int extra=0;
                int kk=r;
                while(temp<=25&& dp[r][temp]<=tt && kk<n){
                    temp++;
                    extra++;
                    kk++;
                }
               // cout<<j<<" "<<r<<" "<<cur<<" "<<extra<<endl;
              //  cout<<i<<" "<<
                res=max(res,cur+extra);
                tt-=dp[r][25];
                cur+=min(limit,n-r);
                while(l<=r && tt<0){
                    cur-=min(26,n-r);
                    tt+=dp[l][25];
                    l+=limit;
                    l=min(n-1,l);
                }
                res=max(res,cur);
                r+=limit;
            }
          }
        }
       cout<<res<<"\n";
     
    }
    
   
   return 0;
    
}
 

Information

Submit By
Type
Submission
Problem
P1068 Alphabetical substring
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-09 12:59:00
Judged At
2024-11-11 03:28:46
Judged By
Score
100
Total Time
855ms
Peak Memory
13.645 MiB