This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n;
int a[maxn], b[maxn];
bool mark[maxn];
string s;
void solve()
{
cin >> n >> s;
for(int i = 0 ; i < n ; i++)
cin >> a[i] >> b[i];
for(int i = 0 ; i < n ; i++)
a[i]--, b[i]--;
for(int mask = 0 ; mask < (1 << n) ; mask++)
{
memset( mark , false , sizeof(mark) );
for(int i = 0 ; i < n ; i++)
mark[ (mask & (1 << i)) ? b[i] : a[i] ] = true;
int sum = 0;
bool good = true;
for(int i = 0 ; i < 2*n ; i++)
{
if( !mark[i] )
continue;
sum += (s[i] == '(') ? 1 : -1;
if( sum < 0 )
good = false;
}
if( sum == 0 && good )
{
for(int i = 0 ; i < n ; i++)
cout << ((mask & (1 << i)) ? 1 : 0) << " ";
cout << endl;
return;
}
}
cout << -1 << endl;
}
int main()
{
int t;
cin >> t;
while( t-- )
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |