#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;
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 |
1 |
Incorrect |
73 ms |
456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |