# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43726 | MatheusLealV | Port Facility (JOI17_port_facility) | C++14 | 900 ms | 24440 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>
#define N 3001
#define mod (1000000000 + 7)
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
int n, ans, block[N][N];
pii v[N];
bool intersect(int i, int j)
{
if(v[j].f < v[i].f) swap(i, j);
if(v[i].f <= v[j].f && v[j].s <= v[i].s) return false;
if(v[i].f < v[j].f && v[j].f < v[i].s) return true;
return false;
}
bool check(int mask)
{
vector<int> A, B;
for(int i = 0; i < n; i++)
{
if(mask & (1<<i)) A.push_back(i + 1);
else B.push_back(i + 1);
}
for(int i = 0; i < A.size(); i++)
{
for(int j = 0; j < A.size(); j++)
{
if(block[ A[i] ][ A[j] ]) return false;
}
}
A = B;
for(int i = 0; i < A.size(); i++)
{
for(int j = 0; j < A.size(); j++)
{
if(block[A[i]][A[j]]) return false;
}
}
return true;
}
void ptr(int mask)
{
for(int i = n - 1; i >= 0; i--) cout<< (mask & (1<<i) ? 1 : 0);
cout<<"\n\n";
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i = 1; i <= n; i++) cin>>v[i].f>>v[i].s;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
block[i][j] = intersect(i, j);
}
}
for(int mask = 0; mask < (1<<n); mask ++) if(check(mask)) ans = (ans + 1)%mod;//ptr(mask);
cout<<ans<<"\n";
}
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... |