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 = 1e5 + 10;
bool temResp = false;
int pos[MAXN][2];
int Marc[2*MAXN];
int atual = 0;
string s;
int resp = 0;
void bt(int id, int N)
{
if (temResp) return;
if (id == N+1)
{
int quant = 0;
for (int i = 1; i <= 2*N; i++)
{
if (Marc[i] == 0) continue;
quant += ((s[i-1] == '(') ? 1 : -1);
if (quant < 0) return;
}
if (quant != 0) return;
resp = atual;
temResp = 1;
return;
}
Marc[pos[id][0]] = 1;
bt(id+1, N);
Marc[pos[id][0]] = 0;
atual += (1 << id);
Marc[pos[id][1]] = 1;
bt(id+1, N);
atual -= (1 << id);
Marc[pos[id][1]] = 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while (T--)
{
int N;
cin >> N;
cin >> s;
for (int i = 1; i <= N; i++)
{
cin >> pos[i][0] >> pos[i][1];
}
bt(1, N);
if (!temResp) cout << "-1" << '\n';
else
{
for (int k = 1; k <= N; k++)
{
cout << ((resp >> k) & 1) << " ";
}
cout << '\n';
}
resp = 0; atual = 0; temResp = 0;
}
}
# | 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... |