Tranvick

Untitled

Dec 29th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #define N 1111111
  4.  
  5. using namespace std;
  6.  
  7. string s;
  8.  
  9. int n,a[37],l,r,k;
  10. long long ans;
  11.  
  12. int f(char c){
  13.     if (c>='0' && c<='9') return c-'0';
  14.     return c-'a'+10;
  15. }
  16.  
  17. int main(void){
  18.     freopen("input.txt","r",stdin);
  19.     freopen("output.txt","w",stdout);
  20.     cin>>n>>k;
  21.     cin>>s;
  22.     r=-1;
  23.     while (r<n-1){
  24.         ++r;
  25.         if (++a[f(s[r])]>k){
  26.             while (l<r && a[f(s[r])]>k){
  27.                 --a[f(s[l])];
  28.                 ++l;
  29.             }
  30.         }
  31.         ans+=r-l+1;
  32.     }
  33.     cout<<ans;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment