Submission #1062336

#TimeUsernameProblemLanguageResultExecution timeMemory
106233612345678Port Facility (JOI17_port_facility)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e3+5, mod=1e9+7; int n, l[nx], r[nx], res=1, cnt, c[nx], f, vs[nx], f2; vector<int> d[nx]; pair<int, int> v[2*nx]; stack<int> a, b; void dfs(int u) { vs[u]=1; for (auto v:d[u]) { if (vs[v]) { if (c[v]==c[u]) f=1; continue; } c[v]=!c[u]; dfs(v); } } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>l[i]>>r[i], v[l[i]]={i, 1}, v[r[i]]={i, 0}; for (int i=1; i<=2*n; i++) { if (v[i].second) { if (a.empty()&&b.empty()) a.push(v[i].first); else if (b.empty()) { if (r[a.top()]>r[v[i].first]) a.push(v[i].first); else b.push(v[i].first); } else if (a.empty()) { if (r[b.top()]>r[v[i].first]) b.push(v[i].first); else a.push(v[i].first); } else { if (max(r[a.top()], r[b.top()])<r[v[i].first]) { f2=1; break; } if (r[a.top()]<r[b.top()]) { if (r[a.top()]>r[v[i].first]) a.push(v[i].first); else b.push(v[i].first); } else { if (r[b.top()]>r[v[i].first]) b.push(v[i].first); else a.push(v[i].first); } } } else { if (!a.empty()&&a.top()==v[i].first) a.pop(); else { if (b.top()!=v[i].first) cout<<1/0; b.pop(); } } } for (int i=1; i<=n; i++) { for (int j=i+1; j<=n; j++) { if ((l[i]<l[j]&&r[j]<r[i])||(l[j]<l[i]&&r[i]<r[j])||r[i]<l[j]||r[j]<l[i]) continue; d[i].push_back(j); d[j].push_back(i); } } for (int i=1; i<=n; i++) if (!vs[i]) dfs(i), res=(res*2)%mod; if (!f&&f2) cout<<1/0; if (f) cout<<1/0; cout<<res; }

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:71:49: warning: division by zero [-Wdiv-by-zero]
   71 |                 if (b.top()!=v[i].first) cout<<1/0;
      |                                                ~^~
port_facility.cpp:86:24: warning: division by zero [-Wdiv-by-zero]
   86 |     if (!f&&f2) cout<<1/0;
      |                       ~^~
port_facility.cpp:87:19: warning: division by zero [-Wdiv-by-zero]
   87 |     if (f) cout<<1/0;
      |                  ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...