This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int tm[2 * n];
for(int i = 1, a, b; i <= n; ++ i) {
cin >> a >> b;
-- a;
-- b;
tm[a] = i + 1;
tm[b] = - (i + 1);
}
if(n < 21) {
ll ans = 0;
for(int msk = (1<<n); msk --> 0;) {
stack < int > A, B;
for(int i = 0; i < 2 * n; ++ i) {
if(tm[i] > 0) {
if((1<<(tm[i] - 1))&msk) {
B.push(tm[i]);
} else {
A.push(tm[i]);
}
} else {
if((1<<(-tm[i] - 1))&msk) {
if(B.empty() || B.top() != -tm[i]) {
goto BREAK;
}
B.pop();
} else {
if(A.empty() || A.top() != -tm[i]) {
goto BREAK;
}
A.pop();
}
}
}
++ ans;
BREAK: {
};
}
cout << ans;
}
}
Compilation message (stderr)
port_facility.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | main() {
| ^~~~
# | 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... |