Please read the new rule regarding the restriction on the use of AI tools. ×

Codeforces round 712:div2

Revision en1, by AnkitaSakseria1, 2021-05-03 17:15:03

This code of mine for problem c:Balance the bits is showing error .Can anyone help me out for which cases its failing?? Problem Link: https://codeforces.me/contest/1504/problem/C

include <bits/stdc++.h>

define mod 1000000007

define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

define T1 ll T; cin>>T; while(T--)

define rep(i,n) for(int i = 0; i < (n); ++i)

define repF(i,a,n) for(int i = (a); i <= (n); ++i)

define repB(i,a,n) for(int i = (a); i >= (n); --i)

define PB push_back

define all(z) z.begin(),z.end()

define ll long long int

define vi vector

define vll vector

using namespace std; int main() { fast; int n; string s, s1, s2; int op1, op2; bool flag; T1 { cin >> n; cin >> s; if (T == 936 || T == 64) { cout << s << '\n'; } s1 = s2 = ""; op1 = op2 = 0; flag = true; rep(i, s.length()) { if (s[i] == '1') { if (op1 == 0 || op2 == 0) { op1 += 1; op2 += 1; s1 += '('; s2 += '('; } else if (op1 > 0 && op2 > 0 ) { op1--; op2--; s1 += ')'; s2 += ')'; } } else { if (op1 == 0 && op2 == 0) { flag = false; break; } else if (op1 >= op2) {

          s1 += ')';
          s2 += '(';
          op1--;
          op2++;
         }
         else {
          s1 += '(';
          s2 += ')';
          op1++;
          op2--;
         }

       }

    }

    if (!flag || op1 != 0 || op2 != 0)
       cout << "NO\n";
    else {
       cout << "YES\n";
       cout << s1 << '\n';
       cout << s2 << '\n';
    }


}
return 0;

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English AnkitaSakseria1 2021-05-03 17:22:15 1397
en1 English AnkitaSakseria1 2021-05-03 17:15:03 1594 Initial revision (published)