竞赛讨论区 > 想问一下大佬们,为啥只能过90%100的样例😭😭😭
头像
乔治躺上
发布于 2020-02-05 15:11
+ 关注

想问一下大佬们,为啥只能过90%100的样例😭😭😭

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f 
typedef long long ll;
const double eps = 1e-8;
const double pi  = acos(-1.0);

ll n, k;
string s;

int main()
{
    scanf("%lld%lld", &n, &k);
    cin >> s;
    
    ll result = 200005;
    ll char_map[128] = {0};
    map<char, int> word_map;
    for(ll i=0; i<s.length(); i++){
        char_map[s[i]]++;
        if(char_map[s[i]] == 1){
            word_map[s[i]] = i;
        }
        else if(char_map[s[i]] == k){
            ll tmp = i-word_map[s[i]]+1;
            if(result > tmp) result=tmp;
            for(ll j=word_map[s[i]]+1; j<=i; j++){
                if(s[j] == s[i]){
                    word_map[s[i]] = j;
                    char_map[s[i]]--;
                    break;
                }
            }
        }
    }
    if(result == 200005) cout << -1 << endl;
    else          cout << result << endl;
    
    return 0;
}

全部评论

(2) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐