제출 #589243

#제출 시각아이디문제언어결과실행 시간메모리
589243FatihSolak친구 (IOI14_friend)C++17
컴파일 에러
0 ms0 KiB
#include "friend.h" #include <bits/stdc++.h> #define N 1005 using namespace std; vector<int> adj[N]; bool vis[N]; int C[N]; int dfs0(int v){ vis[v] = 1; int ret = C[v]; for(auto u:adj[v]){ if(vis[u])continue; ret = max(ret,dfs0(u)); } return ret; } pair<long long,long long> dfs1(int v){ vis[v] = 1; pair<long long,long long> ret = {0,C[v]}; for(auto u:adj[v]){ if(vis[u])continue; auto tmp = dfs1(u); ret.first += tmp.second; ret.second += tmp.first; } ret.second = max(ret.second,ret.first); return ret; } // Find out best sample int findSample(int n,int confidence[],int host[],int protocol[]){ for(int i = 0;i<n;i++){ C[i] = confidence[i]; } int SUBTASK = 1; set<int> s; for(int i = 1;i<n;i++){ s.insert(protocol[i]); } if(n > 10 && s.size() == 2){ SUBTASK = 5; } if(n > 10 && s.size() == 1){ if(*s.begin() == 0){ SUBTASK = 4; } if(*s.begin() == 1){ SUBTASK = 2; } if(*s.begin() == 2){ SUBTASK = 3; } } for(int i = 1;i<n;i++){ if(protocol[i] == 0){ adj[i].push_back(host[i]); adj[host[i]].push_back(i); } if(protocol[i] == 1){ for(auto u:adj[host[i]]){ adj[i].push_back(u); adj[u].push_back(i); } } if(protocol[i] == 2){ for(auto u:adj[host[i]]){ adj[i].push_back(u); adj[u].push_back(i); } adj[i].push_back(host[i]); adj[host[i]].push_back(i); } } if(SUBTASK == 1){ long long ans = 0; for(int mask = 1;mask < (1<<n);mask++){ long long sum = 0; bool ok = 1; for(int i = 0;i<n;i++){ if(mask & (1<<i)){ sum += confidence[i]; for(auto u:adj[i]){ if(mask & ( 1<<u)) ok = 0; } } } if(ok){ ans = max(ans,sum); } } return ans; } if(SUBTASK == 2){ long long sum = 0; for(int i = 0;i<n;i++){ sum += confidence[i]; } return sum; } if(SUBTASK == 3){ long long sum = 0; for(int i = 0;i<n;i++){ if(!vis[i]){ sum += dfs0(i); } } return sum; } if(SUBTASK == 4){ long long sum = 0; for(int i = 0;i<n;i++){ if(!vis[i]){ sum += max(dfs1(i).second); } } return sum; } return 0; }

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

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:113:30: error: no matching function for call to 'max(long long int)'
  113 |     sum += max(dfs1(i).second);
      |                              ^
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:2:
/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:113:30: note:   candidate expects 2 arguments, 1 provided
  113 |     sum += max(dfs1(i).second);
      |                              ^
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:2:
/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:113:30: note:   candidate expects 3 arguments, 1 provided
  113 |     sum += max(dfs1(i).second);
      |                              ^
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:2:
/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:113:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  113 |     sum += max(dfs1(i).second);
      |                              ^
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:2:
/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:113:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  113 |     sum += max(dfs1(i).second);
      |                              ^