Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ss second
  6. #define ff first
  7. #define p_b push_back
  8. #define endl "\n"
  9.  
  10. #ifndef LOCAL
  11. #define cerr if(0)cerr
  12. #endif // LOCAL
  13.  
  14.  
  15. typedef long long ll;
  16. typedef long double ld;
  17.  
  18. const ll INF = 9223372036854775807;
  19. const ll INFINT = 2147483647;
  20. const int N = 1000006;
  21. const int NN = 1006;
  22. const int MOD = 1000000007;
  23.  
  24. void DIE(string s) {
  25. cout << s << endl;
  26. exit(0);
  27. }
  28.  
  29. void DIE(ll x) {
  30. cout << x << endl;
  31. exit (0);
  32. }
  33.  
  34. void DIE(int x) {
  35. cout << x << endl;
  36. exit(0);
  37. }
  38.  
  39. void YES() {
  40. DIE("YES");
  41. }
  42.  
  43. void Yes() {
  44. DIE("Yes");
  45. }
  46.  
  47. void yes() {
  48. DIE("yes");
  49. }
  50.  
  51. void NO() {
  52. DIE("NO");
  53. }
  54.  
  55. void No() {
  56. DIE("No");
  57. }
  58.  
  59. void no() {
  60. DIE("no");
  61. }
  62. /////////////////
  63. // Write below //
  64. /////////////////
  65.  
  66. int main () {
  67. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  68. #ifdef LOCAL
  69. freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
  70. #else
  71. //freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
  72. //freopen ("mole.in", "r", stdin);freopen ("mole.out", "w", stdout);
  73. #endif // LOCAL
  74. int n;
  75. cin >> n;
  76. n <<= 1;
  77. string s;
  78. cin >> s;
  79. int ans = 0;
  80. int bal = 0;
  81. for (int i = 0; i < n; i++) {
  82. if (s[i] == '(') bal++;
  83. else bal--;
  84. if (bal < 0) {
  85. bal += 2;
  86. ans++;
  87. }
  88. }
  89. //cerr << ans << ' ' << bal << endl;
  90. cout << ans + bal / 2;
  91. }
  92. /////////////////
  93. // Write above //
  94. /////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement