fork download
  1. /*
  2.   Author: Nguyen Nhut Truong
  3.   From Chuyen Tien Giang High School For The Gifted
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. //#define int long long
  9. #define start signed main
  10. #define fi first
  11. #define se second
  12. #define pb push_back
  13. #define eb emplace_back
  14. #define il pair<int,ll>
  15. #define ii pair<int,int>
  16. #define len(s) (int)s.size()
  17. #define all(s) (s).begin(),(s).end()
  18. #define OpenFile(Name) if (fopen(Name".inp","r")) freopen(Name".inp","r",stdin),freopen(Name".out","w",stdout);
  19.  
  20. #define MASK(x) ((1LL)<<(x))
  21. #define Bit(x,i) (((x)>>(i))&1)
  22. #define Countbit(x) __builtin_popcountll(x)
  23.  
  24. typedef long long ll;
  25. typedef long double ld;
  26.  
  27. int dx[]={1,-1,0,0,-1,1,1,-1};
  28. int dy[]={0,0,1,-1,-1,-1,1,1};
  29.  
  30. template <class C> bool Minimize(C &a, C b) { if (a>b) { a=b; return true; } return false;}
  31. template <class C> bool Maximize(C &a, C b) { if (a<b) { a=b; return true; } return false;}
  32.  
  33. inline ll add(ll a,ll b,ll c) { return (a+b)%c; };
  34. inline ll suf(ll a,ll b,ll c) { return (a-b+c)%c; };
  35. inline ll mul(ll a,ll b,ll c) { return ((a%c)*(b%c))%c; };
  36.  
  37. mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
  38.  
  39. ll rand(ll l,ll r){
  40. assert(l<=r);
  41. return l+rd()%(r-l+1);
  42. }
  43.  
  44. void MakeInp() {
  45. ofstream cout("Task.inp");
  46.  
  47. cout.close();
  48. }
  49.  
  50. /// Constant Limit
  51.  
  52. const int N=1e6+5,M=1e3+5,INF=1e9,lim=1e6;
  53. const int block=448,base=31;
  54.  
  55. ll Mod=1e9+7,Mod_base=1777777777,LNF=1e18;
  56.  
  57. ///________________________________________________________________________________________________________
  58.  
  59.  
  60. bool check(string s) {
  61. stack<char> a;
  62.  
  63. for (int i=0;i<len(s);++i)
  64. if (s[i]=='(') a.push('('); else {
  65. if (a.empty()) return 0;
  66. a.pop();
  67. }
  68.  
  69. return a.empty();
  70. }
  71.  
  72.  
  73. start() {
  74. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  75. OpenFile("TASK");
  76.  
  77. int n; cin>>n;
  78. string s; cin>>s;
  79.  
  80. if (check(s)) cout<<"YES"; else cout<<"NO";
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. //cerr<<"\nBien dich thanh cong\nTime: "<<(1.0*clock()/CLOCKS_PER_SEC)<<" s\n";
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
YES