# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1062612 | Unforgettablepl | Port Facility (JOI17_port_facility) | C++98 | 1524 ms | 1048576 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;
// #define int long long
const long long modulo = 1e9+7;
const int LIMIT = 1e9;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<pair<int,int>> ships(N);
for(auto&[a,b]:ships)cin>>a>>b;
vector<forward_list<int>> adj(N);
sort(ships.begin(), ships.end());
int edges_added = 0;
set<pair<int,int>> active;
for(int i=0;i<N;i++) {
auto [a,b] = ships[i];
while(!active.empty() and active.begin()->first<a)active.erase(active.begin());
auto final = active.emplace(b,i).first;
for(auto iter=active.begin();iter!=final;++iter) {
edges_added++;
adj[i].emplace_front(iter->second);
adj[iter->second].emplace_front(i);
}
if(edges_added>LIMIT) {
cout << "0\n";
return 0;
}
}
long long ans = 1;
vector<int> visited(N,-1);
bool works = true;
function<void(int,bool)> dfs = [&](int x,bool colour) {
if(visited[x]!=-1) {
if(visited[x]!=(int)colour)works=false;
return;
}
visited[x]=colour;
for(const int&i:adj[x])dfs(i,!colour);
};
for(int i=0;i<N;i++)if(visited[i]==-1){
ans<<=1;
ans%=modulo;
dfs(i,0);
}
if(!works)ans=0;
cout << ans << '\n';
}
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... |