fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5. const ll INF = -10000000000000;
  6.  
  7. void solve() {
  8. string s;
  9. cin >> s;
  10. int n=s.size();
  11. vector<int> balance(n);
  12. int bal=0;
  13. for(int i=0;i<n;i++){
  14. if(s[i]=='(') bal++;
  15. else bal--;
  16. balance[i]=bal;
  17. }
  18. int cnt=0;
  19. for(int i=0;i<n;i++){
  20. if(balance[i]==0){
  21. cnt++;
  22. }
  23. }
  24. if(cnt>=2) cout << "YES\n";
  25. else cout << "NO\n";
  26.  
  27. }
  28.  
  29. int main(){
  30. ios::sync_with_stdio(false);
  31. cin.tie(nullptr);
  32.  
  33. int t;
  34. cin >> t;
  35. while (t--) solve();
  36.  
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5320KB
stdin
4
(())
(())()()
()
(())(())
stdout
NO
YES
NO
YES