# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
967607 | Isam | Superpozicija (COCI22_superpozicija) | C++17 | 169 ms | 604 KiB |
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;
constexpr int sz = 200002;
int n, a[sz], b[sz];
string z;
signed main(){
ios_base::sync_with_stdio(0);
int T;
cin >> T;
function<void()> test_case = [](){
cin >> n >> z;
for(register int i = 1; i <= n; ++i){
cin >> a[i] >> b[i];
a[i]--, b[i]--;
}
assert(n<=10);
for(register int mask = 0; mask < (1 << n); ++mask){
bool flag = true;
int tot(0);
bitset<22> chosen;
for(register int i = 1; i <= n && flag; ++i){
if(mask & (1<<(i-1))){
chosen[b[i]] = true;
}else{
chosen[a[i]] = true;
}
}
for(register int i = 0; i < (n << 1); ++i){
if(chosen[i]) tot += z[i]=='('?1:-1;
flag &= tot>=0;
}
flag &= !tot;
if(flag){
for(register int i = 0; i < n; ++i){
cout << (bool)(mask & (1 << i)) << " \n"[i==n-1];
}
return;
}
}
cout << -1 << '\n';
};
while(T--) test_case();
return 0;
}
Compilation message (stderr)
# | 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... |