fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n, k, m=0 ,ans=0;
  9. string s;
  10. cin >> n >> k;
  11. cin >> s;
  12. for(int i = 0; i < k; i++)m += ( s[i] == '(' ) ? 1 : -1;
  13. k--;
  14. if(s[0] == '(' && s[k] == ')' && m == 0)ans++;
  15. for(int i = 1; i < n-k; i++){
  16. m += ( s[i-1] == '(' ) ? -1 : 1;
  17. m += ( s[i+k] == ')' ) ? -1 : 1;
  18. if(s[i] == ')') continue;
  19. if(s[i+k] == '(') continue;
  20. if(m)continue;
  21. ans++;
  22. };
  23. cout << ans;
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3464KB
stdin
8 6
(())(())
stdout
1