제출 #297024

#제출 시각아이디문제언어결과실행 시간메모리
297024LifeHappen__전선 연결 (IOI17_wiring)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
#include "wiring.h"

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}

#define forinc(a,b,c) for(int a=b, __c=c; a<=__c; ++a)
#define fordec(a,b,c) for(int a=b, __c=c; a>=__c; --a)
#define forv(a,b) for(auto &a:b)

#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define fasty ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))

template<class T> void Max(T &x, T y){
   x = min(x, y);
}

int64_t min_total_length(vector<int> r, vector<int> b){
   vector<ii> p;
   forv(v,r) p.eb(v,0);
   forv(v,b) p.eb(v,1);
   sort(all(p));
   vector<vector<int>> pack;
   vector<vector<int64_t>> f,sum;
   forinc(i,0,p.size()-1){
      vector<int> _;
      int j=i;
      while(j<p.size() && p[i].se==p[j].se) _.pb(p[j++].fi);
      j--;
      i=j;
      pack.pb(_);
   }
   int n=pack.size();
   int64_t INF=1e18;
   forv(v,pack){
      int _=v.size();
      f.pb(vector<int64_t>(_+1,INF));
      sum.pb(vector<int64_t>(_+1));
   }
   forinc(i,0,pack.size()-1){
      forinc(j,1,pack[i].size()){
         sum[i][j]=sum[i][j-1]+pack[i][j-1];
      }
   }
   f[0][0]=0;
   forinc(i,0,n-1){
      int _=pack[i].size();
      forinc(j,0,_-1){
         if(i>0){
            Max(f[i][j+1], f[i][j]+1ll*(pack[i][j]-pack[i-1].back()));
         }
         if(i!=n-1){
            Max(f[i][j+1], f[i][j]+1ll*(pack[i+1][0]-pack[i][j]));
            if(_-j<=pack[i+1].size()) Max(f[i+1][_-j], f[i][j]+sum[i+1][_-j]-sum[i][_]+sum[i][j]);
         }
      }
      if(i<n-1) Max(f[i+1][0], f[i][_]);
      else return f[i][_];
   }
}
/**
int32_t main(){
   int n,m; cin>>n>>m;
   vector<int> a(n), b(m);
   forv(v,a) cin>>v;
   forv(v,b) cin>>v;
   cout<<min_total_length(a,b);
}
*/

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

wiring.cpp:30:9: error: ambiguating new declaration of 'int64_t min_total_length(std::vector<int>, std::vector<int>)'
   30 | int64_t min_total_length(vector<int> r, vector<int> b){
      |         ^~~~~~~~~~~~~~~~
In file included from wiring.cpp:2:
wiring.h:3:11: note: old declaration 'long long int min_total_length(std::vector<int>, std::vector<int>)'
    3 | long long min_total_length(std::vector<int> r, std::vector<int> b);
      |           ^~~~~~~~~~~~~~~~
wiring.cpp: In function 'int64_t min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:40:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |       while(j<p.size() && p[i].se==p[j].se) _.pb(p[j++].fi);
      |             ~^~~~~~~~~
wiring.cpp:62:69: error: no matching function for call to 'Max(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&, long long int)'
   62 |             Max(f[i][j+1], f[i][j]+1ll*(pack[i][j]-pack[i-1].back()));
      |                                                                     ^
wiring.cpp:26:24: note: candidate: 'template<class T> void Max(T&, T)'
   26 | template<class T> void Max(T &x, T y){
      |                        ^~~
wiring.cpp:26:24: note:   template argument deduction/substitution failed:
wiring.cpp:62:69: note:   deduced conflicting types for parameter 'T' ('long int' and 'long long int')
   62 |             Max(f[i][j+1], f[i][j]+1ll*(pack[i][j]-pack[i-1].back()));
      |                                                                     ^
wiring.cpp:65:65: error: no matching function for call to 'Max(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&, long long int)'
   65 |             Max(f[i][j+1], f[i][j]+1ll*(pack[i+1][0]-pack[i][j]));
      |                                                                 ^
wiring.cpp:26:24: note: candidate: 'template<class T> void Max(T&, T)'
   26 | template<class T> void Max(T &x, T y){
      |                        ^~~
wiring.cpp:26:24: note:   template argument deduction/substitution failed:
wiring.cpp:65:65: note:   deduced conflicting types for parameter 'T' ('long int' and 'long long int')
   65 |             Max(f[i][j+1], f[i][j]+1ll*(pack[i+1][0]-pack[i][j]));
      |                                                                 ^
wiring.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             if(_-j<=pack[i+1].size()) Max(f[i+1][_-j], f[i][j]+sum[i+1][_-j]-sum[i][_]+sum[i][j]);
      |                ~~~^~~~~~~~~~~~~~~~~~
wiring.cpp:31:15: warning: control reaches end of non-void function [-Wreturn-type]
   31 |    vector<ii> p;
      |               ^