이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
#define REP(i, n) for(int i = 0;i < n;i ++)
#define REP1(i, n) for(int i = 1;i <= n;i ++)
#define FILL(i, n) memset(i, n, sizeof(i))
#define X first
#define Y second
#define pb push_back
#define SZ(_a) ((int)(_a).size())
#define ALL(_a) (_a).begin(), (_a).end()
#ifdef brian
#define IOS()
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...t>void _do(T &&x, t &&...X){cerr<<x<<", ";_do(X...);}
#define debug(...) {\
fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
_do(__VA_ARGS__);\
}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif
const ll MAXn = 2e3 + 5;
const ll INF = ll(1e18);
const ll MOD = 1000000007;
vector<ll> v[MAXn];
ll in[MAXn], out[MAXn], vis[MAXn];
bool dfs(ll now)
{
for(ll k:v[now])
{
if(vis[k] == vis[now])return 0;
else if(vis[k] == -1)
{
vis[k] = !vis[now];
if(!dfs(k))return 0;
}
}
return 1;
}
int main(){
IOS();
ll n;
cin>>n;
REP1(i, n)cin>>in[i]>>out[i];
REP1(i, n)REP1(j, n)if(in[i] < in[j] && in[j] < out[i] && out[i] < out[j])
{
v[i].pb(j), v[j].pb(i);
debug(i, j);
}
ll ct = 0;
FILL(vis, -1);
REP1(i, n)if(vis[i] == -1)
{
vis[i] = 0;
if(!dfs(i))
{
cout<<0<<endl;
return 0;
}
else ct++;
}
ll tt = 1;
REP1(i, ct)tt = tt * 2 % MOD;
cout<<tt<<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... |