이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#ifdef _DEBUG
#define FILE_IN "input.txt"
#define FILE_OUT "output.txt"
#endif
#include <iostream>
#include <cstdlib>
#include <climits>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
void openFiles() {
#ifdef _DEBUG
assert(freopen(FILE_IN, "r", stdin));
assert(freopen(FILE_OUT, "w", stdout));
#endif
}
void IOoptimize() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
vector<vector<int>> g;
vector<bool> used;
vector<int> color;
ll ans = 1;
void dfs(int i) {
used[i] = true;
if (color[i] == 0)
color[i] = 1;
for (auto j : g[i]) {
if (color[j] == color[i]) {
cout << "0";
exit(0);
}
if (!used[j]) {
color[j] = -color[i];
dfs(j);
}
}
}
int main() {
openFiles();
IOoptimize();
int n;
cin >> n;
g.resize(n);
vector<pair<int, int>> segments;
for (int i = 0; i < n; i++) {
int time1, time2;
cin >> time1 >> time2;
segments.push_back({time1, time2});
}
sort(segments.begin(), segments.end());
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (segments[j].first < segments[i].second && segments[i].second < segments[j].second) {
g[i].push_back(j);
g[j].push_back(i);
//cout << i + 1 << " -> " << j + 1 << "\n";
}
}
}
color.resize(n, 0);
used.resize(n, false);
for (int i = 0; i < n; i++) {
if (!used[i]) {
dfs(i);
ans *= 2;
ans %= mod;
}
}
cout << ans;
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... |