제출 #763510

#제출 시각아이디문제언어결과실행 시간메모리
763510raysh07Catfish Farm (IOI22_fish)C++17
컴파일 에러
0 ms0 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; #define INF (long long)(1e18) const int N = 1e5 + 69; vector <int> ok[N]; map <int, long long> a[N]; unordered_map <int, long long> ac[N]; unordered_map <int, long long> dp[N][2]; vector <int> opt[N]; long long val(int i, int j){ int idx = upper_bound(ok[i].begin(), ok[i].end(), j) - ok[i].begin() - 1; assert(idx >= 0); return ac[i][ok[i][idx]]; } long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) { for (int i = 0; i < m; i++){ a[x[i] + 1][y[i] + 1] = w[i]; ok[x[i] + 1].push_back(y[i] + 1); } ok[0].push_back(0); a[0][0] = 0; ok[n + 1].push_back(0); a[n + 1][0] = 0; ok[n + 2].push_back(0); a[n + 2][0] = 0; for (int i = 0; i < n; i++){ a[i + 1][0] = 0; ok[i + 1].push_back(0); sort(ok[i + 1].begin(), ok[i + 1].end()); long long v = 0; for (auto &[x, y] : a[i + 1]){ v += y; y = v; } } for (int i = 0; i <= n + 2; i++){ for (auto [x, y] : a[i]){ ac[x] = y; } } dp[0][1][0] = dp[0][0][0] = 0; //0, 1 --> not processed / processed opt[0].push_back(0); for (int i = 1; i <= n + 1; i++){ for (int x : ok[i - 1]) opt[i].push_back(x); for (int x : ok[i + 1]) opt[i].push_back(x); sort(opt[i].begin(), opt[i].end()); opt[i].erase(unique(opt[i].begin(), opt[i].end()), opt[i].end()); for (int j : opt[i]){ dp[i][0][j] = dp[i][1][j] = -INF; } if (i != (n + 1)){ for (int j : opt[i]){ if (j == 0) continue; dp[i][0][j] = max(dp[i][0][j], dp[i - 1][0][0] + val(i - 1, j) - val(i, j)); dp[i][0][j] = max(dp[i][0][j], dp[i - 1][1][0] - val(i, j)); } long long mx = -INF; int pt = 1; for (int j : opt[i]){ if (j == 0) continue; while (pt != opt[i - 1].size() && opt[i - 1][pt] <= j){ mx = max(mx, dp[i - 1][0][opt[i - 1][pt]]); pt++; } dp[i][0][j] = max(dp[i][0][j], mx - val(i, j) + val(i - 1, j)); } mx = -INF; pt = opt[i - 1].size() - 1; for (int j : opt[i]){ if (j == 0) continue; while (pt != 0 && opt[i - 1][pt] >= j){ mx = max(mx, dp[i - 1][1][opt[i - 1][pt]]); pt--; } dp[i][1][j] = max(dp[i][1][j], mx - val(i, j) + val(i + 1, j)); } for (int j : opt[i]){ if (j == 0) continue; dp[i][1][j] = max(dp[i][1][j], dp[i][0][j] + val(i, j) + val(i + 1, j)); } } for (int j : opt[i - 1]){ if (j == 0) continue; dp[i][0][0] = max(dp[i][0][0], dp[i - 1][1][j] - val(i, j)); dp[i][1][0] = max(dp[i][1][0], dp[i - 1][1][j]); } dp[i][0][0] = max(dp[i][0][0], dp[i - 1][0][0]); dp[i][0][0] = max(dp[i][0][0], dp[i - 1][1][0]); } long long sum = 0; for (int i = 0; i <= n + 1; i++){ sum += dp[i][0].size(); sum += dp[i][1].size(); } assert(sum <= 2 * (2 * m + n + 2)); long long ans = -INF; ans = max(ans, dp[n + 1][0][0]); ans = max(ans, dp[n + 1][1][0]); return ans; } // int main(){ // int n, m; cin >> n >> m; // vector <int> a(m), b(m), c(m); // for (auto &x : a) cin >> x; // for (auto &x : b) cin >> x; // for (auto &x : c) cin >> x; // cout << max_weights(n, m, a, b, c) << "\n"; // return 0; // }

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

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:45:21: error: no match for 'operator=' (operand types are 'std::unordered_map<int, long long int>' and 'std::tuple_element<1, std::pair<const int, long long int> >::type' {aka 'long long int'})
   45 |             ac[x] = y;
      |                     ^
In file included from /usr/include/c++/10/unordered_map:47,
                 from /usr/include/c++/10/functional:61,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fish.cpp:2:
/usr/include/c++/10/bits/unordered_map.h:271:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&) [with _Key = int; _Tp = long long int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, long long int> >]'
  271 |       operator=(const unordered_map&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:271:17: note:   no known conversion for argument 1 from 'std::tuple_element<1, std::pair<const int, long long int> >::type' {aka 'long long int'} to 'const std::unordered_map<int, long long int>&'
  271 |       operator=(const unordered_map&) = default;
      |                 ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:275:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&&) [with _Key = int; _Tp = long long int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, long long int> >]'
  275 |       operator=(unordered_map&&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:275:17: note:   no known conversion for argument 1 from 'std::tuple_element<1, std::pair<const int, long long int> >::type' {aka 'long long int'} to 'std::unordered_map<int, long long int>&&'
  275 |       operator=(unordered_map&&) = default;
      |                 ^~~~~~~~~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:289:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(std::initializer_list<typename std::_Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc, std::__detail::_Select1st, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__is_nothrow_invocable<const _Hash&, const _Key&> > >::value, false, true> >::value_type>) [with _Key = int; _Tp = long long int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, long long int> >; typename std::_Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc, std::__detail::_Select1st, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__is_nothrow_invocable<const _Hash&, const _Key&> > >::value, false, true> >::value_type = std::pair<const int, long long int>]'
  289 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/unordered_map.h:289:46: note:   no known conversion for argument 1 from 'std::tuple_element<1, std::pair<const int, long long int> >::type' {aka 'long long int'} to 'std::initializer_list<std::pair<const int, long long int> >'
  289 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
fish.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             while (pt != opt[i - 1].size() && opt[i - 1][pt] <= j){
      |                    ~~~^~~~~~~~~~~~~~~~~~~~