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;
int n, a[22], b[22], ans;
int main(){
cin >> n;
for(int i = 0; i < n; i ++){
cin >> a[i] >> b[i];
a[i] --, b[i] --;
}
for(int mask = 0; mask < (1 << n); mask ++){
vector <int> v, add[n + n], del[n + n];
for(int i = 0; i < n; i ++){
if((1 << i) & mask){
add[a[i]].push_back(i);
del[b[i]].push_back(i);
}
}
bool ok = 1;
for(int i = 0; i < n * 2; i ++){
for(int j : add[i])
v.push_back(j);
for(int j : del[i]){
if(v.back() != j){
ok = 0;
break;
}
v.pop_back();
}
add[i].clear();
del[i].clear();
}
for(int i = 0; i < n; i ++){
if(!((1 << i) & mask)){
add[a[i]].push_back(i);
del[b[i]].push_back(i);
}
}
for(int i = 0; i < n * 2; i ++){
for(int j : add[i])
v.push_back(j);
for(int j : del[i]){
if(v.back() != j){
ok = 0;
break;
}
v.pop_back();
}
}
ans += ok;
}
cout << ans << endl;
}
# | 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... |