/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Wrong Answer 342ms 576.0 KiB
#3 Wrong Answer 478ms 572.0 KiB
#4 Wrong Answer 472ms 708.0 KiB
#5 Accepted 697ms 1.867 MiB
#6 Wrong Answer 957ms 13.637 MiB
#7 Accepted 916ms 13.633 MiB
#8 Accepted 946ms 13.641 MiB
#9 Accepted 938ms 13.633 MiB
#10 Accepted 943ms 13.637 MiB
#11 Accepted 899ms 13.641 MiB
#12 Accepted 944ms 13.641 MiB
#13 Accepted 943ms 13.641 MiB
#14 Accepted 955ms 13.641 MiB
#15 Accepted 949ms 13.641 MiB
#16 Accepted 1104ms 13.801 MiB
#17 Accepted 1206ms 13.641 MiB
#18 Accepted 1178ms 13.629 MiB
#19 Accepted 1225ms 13.637 MiB
#20 Accepted 1100ms 13.676 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++;
                }
                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);
                if(r==n-1)break;
                r+=limit;
                r=min(r,n-1);
            }
          }
        }
       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:11:56
Judged At
2024-10-03 13:43:42
Judged By
Score
80
Total Time
1225ms
Peak Memory
13.801 MiB