이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define X real()
#define Y imag()
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
int n;
const int maxn = 4000 + 4;
const int mod = 1e9 + 7;
pii A[maxn]; int ind[maxn];
pii p[maxn]; int num;
pii get(int a) {
if (p[a].F == a) return p[a];
auto x = get(p[a].F); x.S ^= p[a].S;
return (p[a] = x);
}
void merge(int u, int v) {
pii a = get(u), b = get(v);
if (a.F == b.F) {
if (a.S == b.S) kill(0);
return ;
}
p[a.F] = Mp(b.F, (a.S == b.S)); num--;
}
ll power(ll a, ll b) {
if (b == 0) return 1;
return power(a * a % mod, b / 2) * ((b & 1) ? a : 1) % mod;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i].F >> A[i].S;
A[i].F--; A[i].S--;
ind[A[i].F] = i; ind[A[i].S] = i;
}
num = n;
for (int i = 0; i < n; i++) p[i] = Mp(i, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (A[j].F > A[i].F && A[j].F < A[i].S && A[j].S > A[i].S) {
merge(i, j);
}
}
}
cout << power(2, num) << endl;
return 0;
}
# | 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... |