-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (82 loc) · 1.87 KB
/
main.cpp
File metadata and controls
89 lines (82 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <algorithm>
#include <bitset>
#include <vector>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <unordered_map>
#ifndef ONLINE_JUDGE
#include "util.h"
#endif
using namespace ::std;
int dx[4] = {0, 0, 1, -1}; // Up, Down, Right, Left
int dy[4] = {-1, 1, 0, 0}; // Up, Down, Right, Left
// const int N = 3 * 1e4 + 7, M = 250, mod = 1e9 + 7;
#define in(i, j) i >= 0 && i < j
#define not_in(i, j) !(in(i, j))
// int n, l, m;
// string grid[N];
// int dp[N][N];
void solve() {
int n;
cin >> n;
map<int, int> freq;
for (int i = 0; i < n; i++) {
string x;
cin >> x;
int open = 0, close = 0;
for (const char j: x) {
if (j == ')') {
if (open > 0) {
open--;
} else {
close++;
}
} else {
open++;
}
}
if (open != 0 && close != 0) {
} else if (open == 0 && close == 0) {
freq[0]++;
} else if (open == 0) {
freq[close]++;
} else {
freq[open * -1]++;
}
}
for (auto const x: freq) {
if (x.first == 0 || x.second == 0) {
continue;
}
if (freq[x.first * -1] != 0) {
int y = min(freq[x.first], freq[x.first * -1]);
freq[x.first] -= y;
freq[x.first * -1] -= y;
freq[0] += 2 * y;
}
}
cout << freq[0] / 2 << endl;
}
int main() {
#ifndef ONLINE_JUDGE
assert(freopen("input.txt", "rt", stdin));
// freopen("output.txt", "w", stdout);
#endif
int cases = 1;
// cin >> cases;
while (cases--) {
solve();
}
return 0;
}