Submission #865907

#TimeUsernameProblemLanguageResultExecution timeMemory
865907HuyQuang_re_ZeroTeleporters (IOI08_teleporters)C++14
85 / 100
1051 ms65536 KiB
#include <bits/stdc++.h> #define ll long long #define db long double #define N 1000005 #define II pair <int,int> #define III pair <ll,II> #define IV pair <vector <int>,vector <int> > #define fst first #define snd second #define BIT(x,i) ((x>>i)&1) #define Log(x) (31-__builtin_clz((int)x)) #define LogLL(x) (63-__builtin_clzll((ll)x)) #define pi acos(-1) #define to_radian(x) (x*pi/180.0) #define to_degree(x) (x*180.0/pi) using namespace std; int n,m,End[2*N],From[2*N],i,u,sz,l,r,res,nxt[2*N],node,last; bool visited[N]; II a[2*N]; int rev(int u) { return (u<=n) ? u+n : u-n; } int main() { // freopen("teleporters.inp","r",stdin); //freopen("teleporters.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; a[++sz]={ 0,0 }; a[++sz]={ 2000001,2*n+1 }; for(i=1;i<=n;i++) { cin>>l>>r; a[++sz]={ l,i }; a[++sz]={ r,rev(i) }; } sort(a+1,a+sz+1); for(i=2;i<=sz;i++) End[++node]=a[i].snd,From[a[i-1].snd]=node; for(u=1;u<=node;u++) nxt[u]=From[rev(End[u])]; for(u=1;u<node;u=nxt[u]) visited[u]=1,res++; visited[node]=1; priority_queue <int> h; for(u=2;u<=node;u++) if(visited[u]==0) { int v=nxt[u],edge=0; while(v!=u) visited[v]=1,edge++,v=nxt[v]; visited[v]=1,edge++; h.push(edge); } for(i=1;i<=m;i++) if(h.size()>0) { int k=h.top(); h.pop(); res+=k+2; } else { res++; h.push(1); } cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...