제출 #1034936

#제출 시각아이디문제언어결과실행 시간메모리
1034936vjudge1Ancient Books (IOI17_books)C++17
50 / 100
771 ms97188 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; int par[1001000],sz[1001000]; int abp(int n){ return par[n]?par[n]=abp(par[n]):n; } int merge(int a,int b){ a=abp(a+1);b=abp(b+1); if(a-b)par[a]=b, sz[b]+=sz[a]; return a!=b; } set<int>notanedge; map<int,int>mp; void mergefrom(int l,int r){ while(notanedge.lower_bound(l)!=notanedge.lower_bound(r)){ int k=*notanedge.lower_bound(l); merge(k,k+1); notanedge.erase(k); mp[k];mp[k+1]; } } long long minimum_walk(std::vector<int> p, int s) { long long ans=0; int n=p.size(),K=0; for(int i=0;i<n-1;i++) notanedge.insert(i); for(int i=0;i<n;i++) if(i-p[i]) ans+=abs(i-p[i]), mergefrom(i,p[i]); vector<tuple<int,int,int>>v; mp[s]; for(auto [i,j]:mp){ auto it=mp.upper_bound(i); if(it!=mp.end()) v.push_back({it->first-i,i,it->first}); } sort(v.begin(),v.end()); for(auto [w,x,y]:v) ans+=w*2*merge(x,y); return ans; }

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

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:26:20: warning: unused variable 'K' [-Wunused-variable]
   26 |     int n=p.size(),K=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...
#Verdict Execution timeMemoryGrader output
Fetching results...