제출 #316096

#제출 시각아이디문제언어결과실행 시간메모리
316096moonrabbit2Roller Coaster Railroad (IOI16_railroad)C++17
컴파일 에러
0 ms0 KiB
#include "railroad.h" #include <bits/stdc++.h> #define N 500005 #define x first #define y second using namespace std; typedef long long ll; typedef pair<int,int> P; struct edge{ll c;int u,v;}; int n,c,group[N],c_g,p[N],en,x; ll ans,sum[N],from[N]; vector<int> vec; vector<int> g1[N]; edge g2[N]; int fi(int x) { if(p[x]==x) return x; return p[x]=fi(p[x]); } void un(int x,int y) { x=fi(x),y=fi(y); if(x==y) return; p[y]=x; } void dfs(int curr) { group[curr]=c_g; for(auto &it : g1[curr]){ if(!group[it]) dfs(it); } } bool sortf(edge e1,edge e2){return e1.c<e2.c;} ll plan_roller_coaster(vector<int> s,vector<int> t) { n=s.size(); for(int i=0;i<n;i++){ vec.emplace_back(s[i]); vec.emplace_back(t[i]); } vec.emplace_back(1); sort(vec.begin(),vec.end()); vec.resize(unique(vec.begin(),vec.end())); c=vec.size(); for(int i=1;i<=n;i++) from[i]=vec[i-1]; for(int i=0;i<n;i++){ s[i]=lower_bound(vec.begin(),vec.end(),s[i])-vec.begin()+1; t[i]=lower_bound(vec.begin(),vec.end(),t[i])-vec.begin()+1; } sum[2]--; g1[c].push_back(1); for(int i=0;i<n;i++){ sum[s[i]+1]++; sum[t[i]+1]--; g1[s[i]].emplace_back(t[i]); } for(int i=2;i<=c;i++){ sum[i]+=sum[i-1]; if(sum[i]<0) g1[i-1].push_back(i); if(sum[i]>0){ g1[i].push_back(i-1); ans+=sum[i]*(from[i]-from[i-1]); } } for(int i=1;i<=c;i++){ if(group[i]) continue; c_g++; p[c_g]=c_g; dfs(i); } for(int i=2;i<=c;i++){ if(group[i-1]!=group[i]){ g2[++en]={from[i]-from[i-1],group[i-1],group[i]}; } } sort(g2+1,g2+1+en,sortf); for(int i=1;i<=en;i++){ int u=g2[i].u,v=g2[i].v; if(fi(u)==fi(v)) continue; ans+=g2[i].c; un(u,v); } return ans; }

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

railroad.cpp: In function 'll plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:45:71: error: no matching function for call to 'std::vector<int>::resize(__gnu_cxx::__normal_iterator<int*, std::vector<int> >)'
   45 |  sort(vec.begin(),vec.end()); vec.resize(unique(vec.begin(),vec.end()));
      |                                                                       ^
In file included from /usr/include/c++/9/vector:67,
                 from railroad.h:3,
                 from railroad.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:934:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
  934 |       resize(size_type __new_size)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:934:24: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
  934 |       resize(size_type __new_size)
      |              ~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:954:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int]'
  954 |       resize(size_type __new_size, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:954:7: note:   candidate expects 2 arguments, 1 provided