fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. const int N = 1e6 + 5;
  6.  
  7. string a;
  8.  
  9. int cal(int s, int e) {
  10. if (s >= a.size() || s >= e || e < 0) return 0;
  11. else {
  12. int op = 0, p = -1;
  13. for (int i = s + 1; i < e; ++i) {
  14. if (a[i] == '(') op++;
  15. else if (a[i] == ')') op--;
  16. if (op == 0) {
  17. p = i;
  18. break;
  19. }
  20. }
  21. int ans1 = cal(s + 1, p);
  22. if (p + 2 < e && a[p + 1] == '-' && a[p + 2] == '>')
  23. return max(ans1 + 1, cal(p + 3, e - 1));
  24. return ans1;
  25. }
  26. }
  27.  
  28. void solve() {
  29. cin >> a;
  30. a = '(' + a;
  31. a = a + ')';
  32. cout << cal(0, a.size() - 1);
  33. }
  34.  
  35. signed main() {
  36. cin.tie(0) -> sync_with_stdio(0);
  37. int tc = 1;
  38. // cin >> tc;
  39. while (tc--) solve();
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty