Submission #120374

#TimeUsernameProblemLanguageResultExecution timeMemory
120374tinderPort Facility (JOI17_port_facility)C++14
22 / 100
6081 ms41212 KiB
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; const int maxn = 1e6 + 6; int n, s[maxn], t[maxn]; vector<int> g[maxn]; int lvl[maxn], vis[maxn]; bool check(int source) { queue<int> Q; vis[source] = 1; Q.push(source); while(Q.size()) { int u = Q.front(); Q.pop(); for(int v : g[u]) { if(vis[v]) { if(lvl[v] == lvl[u]) { return false; } } else { lvl[v] = lvl[u] + 1; vis[v] = 1; Q.push(v); } } } return true; } int main(int argc, char const *argv[]) { scanf("%d", &n); vector<ii> tmp; for(int i = 1; i <= n; i++) { int _s, _t; scanf("%d %d", &_s, &_t); tmp.emplace_back(_s, _t); } // sort(tmp.begin(), tmp.end()); for(int i = 0; i < n; i++) { s[i + 1] = tmp[i].first; t[i + 1] = tmp[i].second; } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(s[i] < s[j] and s[j] < t[i] and t[i] < t[j]) { g[i].emplace_back(j); g[j].emplace_back(i); } } } const int mod = 1e9 + 7; int ans = 1; for(int i = 1; i <= n; i++) { if(!vis[i]) { if(!check(i)) { puts("0"); return 0; } else { ans <<= 1; if(ans >= mod) { ans -= mod; } } } } printf("%d\n", ans); return 0; }

Compilation message (stderr)

port_facility.cpp: In function 'int main(int, const char**)':
port_facility.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
port_facility.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &_s, &_t);
   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...