Submission #1298757

#TimeUsernameProblemLanguageResultExecution timeMemory
1298757nguyenkhangninh99Džumbus (COCI19_dzumbus)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int maxn = 1e3 + 5, inf = 1e9; vector<int> g[maxn]; int dp[maxn][maxn][2][2], vis[maxn], val[maxn], sz[maxn]; void dfscc(int u){ vis[u] = 1; for(int v: g[u]) if(!vis[v]) dfscc(v); } //dp u c i j. subtree u chọn c thằng (u có chọn không(i)). (có được kết nối không(j)) void dfs(int u, int p){ for(int c = 0; c < maxn; c++) for(int i: {0, 1}) for(int j: {0, 1}) dp[u][c][i][j] = inf; dp[u][0][1][0] = val[u]; dp[u][0][0][0] = 0; sz[u] = 1; for(int v: g[u]){ if(v != p){ dfs(v, u); for(int sz1 = sz[u]; sz1 >= 0; sz1--){ for(int i1: {0, 1}){ for(int j1: {0, 1}){ for(int sz2 = sz[v]; sz2 >= 0; sz2--){ for(int i2: {0, 1}){ for(int j2: {0, 1}){ int nwu = u; int nwc = sz1 + sz2 + (i1 && i2) * ((j1 == 0) + (j2 == 0)); int nwi = i1; int nwj = j1 | (i1 && i2); dp[nwu][nwc][nwi][nwj] = min(dp[nwu][nwc][nwi][nwj], dp[u][sz1][i1][j1] + dp[v][sz2][i2][j2]); } } } } } } } sz[u] += sz[v]; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for(int i = 1; i <= n; i++) cin >> val[i]; for(int i = 1; i <= n - 1; i++){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for(int i = 1; i <= n; i++){ if(vis[i]) continue; dfscc(i); g[0].push_back(i); } dfs(0, -1); vector<int> res(n + 1); for(int i = n; i >= 0; i--) res[i] = dp[0][i][0][0]; for(int i = n - 1; i >= 0; i--) res[i] = min(res[i], res[i + 1]); int q; cin >> q; while(q--){ int s; cin >> s; cout << max(0LL, upper_bound(res.begin(), res.end(), s) - res.begin() - 1) << "\n"; } }

Compilation message (stderr)

dzumbus.cpp: In function 'int main()':
dzumbus.cpp:70:20: error: no matching function for call to 'max(long long int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   70 |         cout << max(0LL, upper_bound(res.begin(), res.end(), s) - res.begin() - 1) << "\n";
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from dzumbus.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
dzumbus.cpp:70:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   70 |         cout << max(0LL, upper_bound(res.begin(), res.end(), s) - res.begin() - 1) << "\n";
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
dzumbus.cpp:70:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   70 |         cout << max(0LL, upper_bound(res.begin(), res.end(), s) - res.begin() - 1) << "\n";
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
dzumbus.cpp:70:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   70 |         cout << max(0LL, upper_bound(res.begin(), res.end(), s) - res.begin() - 1) << "\n";
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
dzumbus.cpp:70:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   70 |         cout << max(0LL, upper_bound(res.begin(), res.end(), s) - res.begin() - 1) << "\n";
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~