forked from 21171-somesh/CodeforcesSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1214C.cpp
More file actions
43 lines (41 loc) · 736 Bytes
/
1214C.cpp
File metadata and controls
43 lines (41 loc) · 736 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, l = 0, r = 0;
string s;
cin >> n >> s;
if(n%2 != 0) {
cout << "No";
return 0;
}
stack<char>k;
for(int i = 0; i < n; i++) {
if((!k.empty()) && k.top() == '(' && s[i] == ')') {
k.pop();
}
else {
k.push(s[i]);
}
if(s[i]==')') {
l++;
}
else {
r++;
}
}
if(l != r) {
cout << "No";
return 0;
}
long cnt=0;
while(!k.empty()) {
k.pop();
cnt++;
if(cnt>2) {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}