数据太水了吧,直接string硬判都能90pts(O2)
查看原帖
数据太水了吧,直接string硬判都能90pts(O2)
577999
Happy_GG楼主2022/8/21 20:28

如题

本想先打个string看看能水多少 个位数 的牛奶质量,没想到直接90pts(O2),Wa的#3 还是与答案只差1

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e4+10;
ll a[N];
string b=" ";
int n,k;
bool check(int len){
    map <string,int> g;
    for(int l=1,r=1+len-1;l<=n-len+1;l++,r++){
        string tp="";
        for(int i=l;i<=r;i++) tp+=b[i];
        g[tp]++;
        if(g[tp]>=k) return true;
    }
    return false;
}
int main(){
    scanf("%d%d",&n,&k);
    string tp;
    for(int i=1;i<=n;i++){
        cin>>tp;
        b+=tp;
    }
    int l=1,r=n;
    int ans=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)) l=mid+1,ans=max(ans,mid);
        else r=mid-1;
    }
    cout<<ans;

    return 0;
}
2022/8/21 20:28
加载中...