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];
vector<int> atual;
string s;
vector<int> resp;
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;
if (s[i-1] == '(') quant++;
else quant--;
if (quant < 0) return;
}
if (quant != 0) return;
for (auto a : atual) resp.push_back(a);
temResp = 1;
return;
}
atual.push_back(0);
Marc[pos[id][0]] = 1;
bt(id+1, N);
atual.pop_back();
Marc[pos[id][0]] = 0;
atual.push_back(1);
Marc[pos[id][1]] = 1;
bt(id+1, N);
atual.pop_back();
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 (auto r : resp) cout << r << " ";
cout << '\n';
}
resp.clear(); atual.clear(); temResp = 0; s.clear();
for (int i = 1; i <= N; i++) {pos[i][0] = pos[i][1] = 0; Marc[i] = Marc[2*i] = 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... |