fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <fstream>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <cmath>
  8. #include <ctime>
  9. #include <map>
  10. #include <unordered_map>
  11. #include <stack>
  12. #include <cstring>
  13. #include <string>
  14. #include <set>
  15. #include <unordered_set>
  16. #include <bitset>
  17. #include <limits>
  18. #include <climits>
  19. #include <queue>
  20. #include <deque>
  21. #include <list>
  22. #include <forward_list>
  23. #include <sstream>
  24. #include <complex>
  25. #include <iterator>
  26. #include <functional>
  27. #include <tuple>
  28. #include <array>
  29. #include <locale>
  30. #include <memory>
  31. #include <cstdio>
  32. #define fin freopen("input.txt", "r", stdin);
  33. #define fout freopen("output.txt", "w", stdout);
  34. #define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  35. #define cp(x) cout.setf(ios::fixed); cout.precision(x);
  36. #define loop(i, x, n) for(int i = x; i <= n; ++i)
  37. #define sz(x) (int)(x).size()
  38. #define all(x) (x).begin(), (x).end()
  39. #define rall(x) (x).rbegin(), (x).rend()
  40. #define mem(a,b) memset(a, b, sizeof(a))
  41. #define cpy(a,b,x) memcpy(a, b, sizeof(x))
  42. #define ST(N) srand(time(NULL))
  43. #define SQ(x) (x)*(x)
  44. #define ad push_back
  45. #define mp make_pair
  46. #define fr first
  47. #define sc second
  48. #define vc vector
  49. #define vi vector<int>
  50. #define pqi priority_queue<int>
  51. #define pii pair<int, int>
  52. #pragma warning(disable:4996)
  53. #pragma comment(linker, "/STACK:336777216")
  54. //#define DEBUG
  55. //#define TEST 1
  56. typedef long long ll;
  57. typedef long double ld;
  58. typedef double dbl;
  59. typedef unsigned long long ull;
  60. using namespace std;
  61.  
  62. const int N = (int)1e6 + 100;
  63. const int MOD = (int)1e9 + 7;
  64. const int INF = INT_MAX;
  65. const ll INF_ll = LLONG_MAX;
  66. const ull INF_ull = ULLONG_MAX;
  67.  
  68. long long cnt = 0, ans = 0;
  69. vector <int> dp(N);
  70. bool u = false, U[N];
  71. int a[N], b[N], c[N];
  72. int A[N / 1000][N / 1000];
  73.  
  74. int gcd(const int x, const int y) {
  75. return y ? gcd(y, x % y) : x;
  76. }
  77.  
  78. bool is_even(int x) {
  79. return 1 - (x & 1);
  80. }
  81.  
  82. int main() {
  83. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  84.  
  85. //#define FREOPEN
  86. #ifdef FREOPEN
  87. #ifndef _MSC_VER
  88. #define TASK ""
  89. freopen(TASK".in", "r", stdin);
  90. freopen(TASK".out", "w", stdout);
  91. #endif
  92. #endif
  93.  
  94. string s;
  95. cin >> s;
  96. int i, j, ans = 0;
  97. for (i = 0; i<s.length(); i++)
  98. {
  99. int p = 0, x = 0;
  100. for (j = i; j<s.length(); j++)
  101. {
  102. if (s[j] == '(') p++;
  103. if (s[j] == ')') p--;
  104. if (s[j] == '?')
  105. {
  106. x++;
  107. p--;
  108. }
  109. if (p == 0) ans++;
  110. if (p<0)
  111. {
  112. if (x == 0) break;
  113. x--;
  114. p += 2;
  115. }
  116. }
  117. }
  118. cout << ans << endl;
  119.  
  120. return 0;
  121. }
  122.  
Success #stdin #stdout 0s 6516KB
stdin
((?))
stdout
4