제출 #245608

#제출 시각아이디문제언어결과실행 시간메모리
245608cki86201Port Facility (JOI17_port_facility)C++11
0 / 100
22 ms23936 KiB
#include <bits/stdc++.h> using namespace std; #define Fi first #define Se second typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define all(x) (x).begin(), (x).end() #define pb push_back #define szz(x) (int)(x).size() #define rep(i, n) for(int i=0;i<(n);i++) typedef tuple<int, int, int> t3; int N, X[2000020], A[1000010], B[1000010]; pii seg[1000010]; vector <int> E[1000010]; int pp[1000010], vis[1000010]; int Find(int x) { return pp[x] == x ? x : pp[x] = Find(pp[x]); } vector <pii> edge; void dfs(int x, int c) { vis[x] = c; for(int e : E[x]) if(!vis[e]) dfs(e, 3 - c); } int main() { scanf("%d", &N); for(int i=1;i<=N;i++) scanf("%d%d", A+i, B+i); for(int i=1;i<=N;i++) X[A[i]] = -i, X[B[i]] = i, seg[i] = {B[i], B[i]}; vector <pii> w; for(int i=1;i<=N;i++) pp[i] = i; for(int i=1;i<=2*N;i++) { int v = X[i]; if(v < 0) w.pb({-v, 1}); else { int a = Find(v), px = -1, cnt = 0; while(szz(w) && w.back().Fi != a) { int pa = w.back().Fi; cnt += w.back().Se; edge.pb({pa, a}); if(px != -1) { pp[px] = pa; if(seg[pa].Fi < seg[px].Se) { puts("0"); return 0; } seg[pa].Fi = seg[px].Fi; } px = pa; w.pop_back(); } if(w.back().Se > 1) --w.back().Se; else w.pop_back(); if(px != -1) w.pb({px, cnt}); } } for(auto &[x, y] : edge) x = Find(x), y = Find(y), E[x].pb(y), E[y].pb(x); int ans = 1; for(int i=1;i<=N;i++) if(pp[i] == i && !vis[i]) { dfs(i, 1); ans = ans * 2 % 1000000007; } for(int i=1;i<=N;i++) for(int e : E[i]) if(vis[i] == vis[e]) ans = 0; printf("%d\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

port_facility.cpp: In function 'int main()':
port_facility.cpp:56:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
  for(auto &[x, y] : edge) x = Find(x), y = Find(y), E[x].pb(y), E[y].pb(x);
            ^
port_facility.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
port_facility.cpp:28:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++) scanf("%d%d", A+i, B+i);
                        ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...