제출 #702001

#제출 시각아이디문제언어결과실행 시간메모리
702001PCTprobability친구 (IOI14_friend)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; using ll = long long; #define pb push_back vector<int> g[100000]; int dp[100000][2]; int con[100000]; void dfs(int a,int b){ for(auto e:g[a]){ if(e==b) continue; dfs(e,a); dp[a][0]+=max(dp[e][0],dp[e][1]); dp[a][1]+=dp[e][0]; } dp[a][1]+=con[a]; } int findSample(int n, int confidence[], int host[], int protocol[]){ for(int i=0;i<n;i++) con[i]=confidence[i]; bool allzero=true; for(int i=1;i<n;i++){ if(protocol[i]!=0) allzero=false; } bool alltwo=true; for(int i=1;i<n;i++){ if(protocol[i]!=2) alltwo=false; } if(alltwo){ ll ans=0; for(int i=0;i<n;i++) ans=max(ans,con[i]); return ans; } if(allzero){ for(int i=1;i<n;i++){ g[host[i]].pb(i); g[i].pb(host[i]); } dfs(0,-1); return max(dp[0][0],dp[0][1]); } assert(n<=10); vector<vector<int>> a(n,vector<int>(n)); for(int i=1;i<n;i++){ if(protocol[i]==0){ a[i][host[i]]=a[host[i]][i]=1; } if(protocol[i]==1){ for(int j=0;j<n;j++){ if(a[host[i]][j]){ a[i][j]=a[j][i]=1; } } } if(protocol[i]==2){ for(int j=0;j<n;j++){ if(a[host[i]][j]){ a[i][j]=a[j][i]=1; } } a[i][host[i]]=a[host[i]][i]=1; } } int ans=0; for(int i=0;i<(1<<n);i++){ int sum=0,ok=1; for(int j=0;j<n;j++){ if((i>>j)&1){ sum+=confidence[j]; for(int k=j+1;k<n;k++){ if((i>>k)&1){ if(a[j][k]) ok=0; } } } } ans=max(ans,sum*ok); } return ans; }

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

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:30:44: error: no matching function for call to 'max(ll&, int&)'
   30 |     for(int i=0;i<n;i++) ans=max(ans,con[i]);
      |                                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
friend.cpp:30:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   30 |     for(int i=0;i<n;i++) ans=max(ans,con[i]);
      |                                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
friend.cpp:30:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   30 |     for(int i=0;i<n;i++) ans=max(ans,con[i]);
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
friend.cpp:30:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |     for(int i=0;i<n;i++) ans=max(ans,con[i]);
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
friend.cpp:30:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |     for(int i=0;i<n;i++) ans=max(ans,con[i]);
      |                                            ^