Submission #865923

#TimeUsernameProblemLanguageResultExecution timeMemory
865923HuyQuang_re_ZeroTeleporters (IOI08_teleporters)C++14
100 / 100
287 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,cnt[2*N]; bool visited[2*N]; int a[2*N],pos[2*N]; int rev(int u) { return (u<=n) ? u+n : u-n; } void Radix_sort(int a[],int &n) { memset(cnt,0,sizeof(cnt)); for(i=1;i<=n;i++) cnt[a[i]]++; n=0; for(i=0;i<=2000001;i++) while(cnt[i]--) a[++n]=i; } int main() { // freopen("teleporters.inp","r",stdin); // freopen("teleporters.out","w",stdout); cin>>n>>m; a[++sz]=0; pos[0]=0; a[++sz]=2000001; pos[2000001]=2*n+1; for(i=1;i<=n;i++) { scanf("%d%d",&l,&r); a[++sz]=l; pos[l]=i; a[++sz]=r; pos[r]=rev(i); } Radix_sort(a,sz); for(i=2;i<=sz;i++) End[++node]=pos[a[i]],From[pos[a[i-1]]]=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; vector <int> val; 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++; val.push_back(edge); } sort(val.begin(),val.end()); for(i=1;i<=m;i++) if(val.size()>0) { int k=val.back(); val.pop_back(); res+=k+2; } else { res++; val.push_back(1); } cout<<res; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d%d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~
#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...