Advertisement
Goga21

Untitled

Apr 5th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7.  
  8. int is_correct_bracket_seq(string s, stack<char> bracket) {
  9. int ans = 0;
  10. for (int i = 0; i < s.size(); i++) {
  11. if (s[i] == '(') {
  12. bracket.push(s[i]);
  13. }else{
  14. if(bracket.empty()){
  15. return 0;
  16. }else if (s[i] == ')' && bracket.top() == '('){
  17. ans++;
  18. bracket.pop();
  19. }else{
  20. break;
  21. }
  22. }
  23. }
  24. return ans;
  25. }
  26.  
  27. signed main(){
  28. ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  29. string s;
  30. cin >> s;
  31. int mx = 0, cnt = 1;
  32. stack<char> v;
  33. for(int i = 0; i < s.size(); i++){
  34. int ans = is_correct_bracket_seq(s.substr(i, s.size()), v);
  35. if(ans > mx){
  36. mx = ans;
  37. cnt = 1;
  38. }else if(ans == mx){
  39. cnt++;
  40. }
  41. }
  42. if(mx == 0){
  43. cout << 0 << ' ' << 1;
  44. }else cout << mx << " " << cnt;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement