# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
318937 | arnold518 | Port Facility (JOI17_port_facility) | C++14 | 6043 ms | 41444 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
const ll MOD = 1e9+7;
int N;
pii A[MAXN+10];
vector<int> adj[MAXN+10];
int vis[MAXN+10];
bool flag=true;
void dfs(int now, int col)
{
vis[now]=col;
for(auto nxt : adj[now])
{
if(vis[nxt]==0) dfs(nxt, 3-col);
else if(vis[nxt]!=3-col) flag=false;
}
}
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
for(int i=1; i<=N; i++)
{
for(int j=1; j<=N; j++)
{
if(i==j) continue;
if(A[i].first<A[j].first && A[j].first<A[i].second && A[i].second<A[j].second)
{
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
ll ans=1;
for(int i=1; i<=N; i++)
{
if(vis[i]) continue;
dfs(i, 1);
ans*=2;
ans%=MOD;
}
if(!flag) printf("0\n");
else printf("%lld\n", ans);
}
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... |