Submission #227285

#TimeUsernameProblemLanguageResultExecution timeMemory
227285stefanbalaz2Port Facility (JOI17_port_facility)C++14
22 / 100
6063 ms9464 KiB
/* */ #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back ///#define ll long long typedef pair<int,int> pii; const int maxn=1e6+10; int mod=1e9+7; int n,kolko,rez,sz[maxn],cc,levi[maxn]; pii niz[2*maxn],p[maxn]; void reset(){ for(int i=1;i<=n;i++){ p[i]={i,0}; sz[i]=1; } cc=n; } pii root(int x){ if(p[x].ff==x)return p[x]; else{ pii pom=root(p[x].ff); p[x]={pom.ff,(p[x].ss^pom.ss)}; return p[x]; } } int join(int x,int y){ pii rx=root(x); pii ry=root(y); if(rx.ff==ry.ff){ if(rx.ss==ry.ss)return 1; else return 0; } if(sz[rx.ff]<sz[ry.ff])swap(rx,ry),swap(x,y); cc--; p[ry.ff]={rx.ff,(rx.ss^ry.ss^1)}; sz[rx.ff]+=sz[ry.ff]; return 0; } int main(){ ///freopen("test.txt","r",stdin); clock_t start=clock(); scanf("%d",&n); reset(); for(int i=1;i<=n;i++){ int a,b; scanf("%d %d",&a,&b); niz[a]={i,1}; niz[b]={i,-1}; levi[i]=a; } set<pii>st; rez=1; for(int i=1;i<=2*n;i++){ if(niz[i].ss>0)st.insert({i,niz[i].ff}); else{ int id=niz[i].ff; int lb=levi[id]; set<pii>::iterator it=st.find({levi[id],id}); it++; ///printf("%d AAAAA\n",id); for(;it!=st.end();it++){ int id2=(*it).ss; ///printf("%d AFSAFSAFSAFAS\n",id2); if(join(id,id2)==1){ printf("0\n"); return 0; } } st.erase(st.find({lb,id})); /* clock_t sad=clock(); if((double)(sad-start)/CLOCKS_PER_SEC>5){ printf("0\n"); return 0; }*/ } } for(int i=1;i<=cc;i++){ rez+=rez; if(rez>=mod)rez-=mod; } printf("%d\n",rez); return 0; }

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:55:13: warning: unused variable 'start' [-Wunused-variable]
     clock_t start=clock();
             ^~~~~
port_facility.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
port_facility.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...