fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int n,k;
  9. cin>>n>>k;
  10. vector<int> nums(n);
  11. for(int i=0;i<n;i++){
  12. cin>>nums[i];
  13. }
  14.  
  15. int i=0;
  16. int j=0;
  17.  
  18. int prev=0;
  19. int ans=0;
  20.  
  21. for(int m=1;m<=10;m++){
  22. int size = m*k;
  23. i=0;
  24. j=0;
  25. vector<int> arr(10,0);
  26. while(j<n){
  27. bool vl=true;
  28. arr[nums[j]]++;
  29.  
  30. if(j-i+1>size){
  31. arr[nums[i]]--;
  32. i++;
  33.  
  34. }
  35.  
  36. for(int x=0;x<10;x++){
  37. if(arr[x]==0){
  38. continue;
  39. }
  40. if(arr[x]!=k){
  41. vl=false;
  42. }
  43. }
  44. if(vl && j-i+1==size){
  45. ans++;
  46. }
  47. j++;
  48.  
  49. }
  50. }
  51.  
  52. cout<<ans<<endl;
  53.  
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5348KB
stdin
7 2 
1 1 0 2 0 2 1
stdout
4