이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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], cor[N], qtd, pot[N], edge = 0;
pii v[N];
bool nope = false;
vector<int> grafo[N];
struct line
{
int pos, id, tip;
bool operator < (const line &ll) const
{
if(pos != ll.pos) return pos < ll.pos;
return tip > ll.tip;
}
};
vector<line> sweep;
bool cmp(pii a, pii b)
{
if(a.f != b.f) return a.f < b.f;
return a.s > b.s;
}
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;
}
void dfs_color(int x)
{
for(auto v: grafo[x])
{
if(cor[v] == cor[x])
{
nope = true;
return;
}
if(cor[v] != -1) continue;
cor[v] = (cor[x] + 1)%2;
dfs_color(v);
}
}
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;
sweep.push_back( { v[i].f, i, 0 } );
sweep.push_back( { v[i].s, i, 1 } );
}
sort(sweep.begin(), sweep.end());
set< pii > open;
for(int i = 0; i < sweep.size(); i++)
{
int x = sweep[i].pos, id = sweep[i].id, tip = sweep[i].tip;
if(!tip)
{
open.insert( {x, id} );
}
else
{
open.erase( {v[id].f, id } );
if(open.size())
{
auto it = open.begin();
int ini = (*it).f, jd = (*it).s;
if(v[id].f < ini && ini < x)
{
edge ++;
grafo[id].push_back(jd);
grafo[jd].push_back(id);
}
}
for(auto it = open.upper_bound( {x, 0} ); it != open.begin() ; it--)
{
int ini = (*it).f, jd = (*it).s;
if(it == open.end()) continue;
if(v[id].f < ini && ini < x)
{
edge ++;
grafo[id].push_back(jd);
grafo[jd].push_back(id);
}
}
}
}
pot[0] = 1;
for(int i = 1; i <= n; i++) pot[i] = (2*pot[i - 1])%mod;
memset(cor, -1, sizeof cor);
for(int i = 1; i <= n; i++)
{
if(cor[i] == -1)
{
qtd ++;
cor[i] = 0;
dfs_color(i);
}
}
cout<<(nope ? 0 : pot[qtd])<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In function 'int main()':
port_facility.cpp:87:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < sweep.size(); i++)
^
# | 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... |