Submission #1078694

#TimeUsernameProblemLanguageResultExecution timeMemory
1078694The_SamuraiCatfish Farm (IOI22_fish)C++17
9 / 100
72 ms30804 KiB
#include "fish.h" #include "bits/stdc++.h" using namespace std; using ll = long long; #define ff first #define ss second long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { vector<vector<pair<int, int>>> a(n); for (int i = 0; i < m; i++) a[X[i]].emplace_back(Y[i] + 1, W[i]); vector<vector<pair<int, ll>>> dp(n), dp2(n), pref(n); for (int x = 0; x < n; x++) { sort(a[x].begin(), a[x].end()); a[x].emplace_back(n + 1, 0); ll sum = 0; for (auto [y, w]: a[x]) { sum += w; pref[x].emplace_back(y, sum); } } auto get = [&](int x, int l, int r) -> ll { if (l > r) return 0; int i = lower_bound(pref[x].begin(), pref[x].end(), make_pair(l, 0ll)) - pref[x].begin(); int j = upper_bound(pref[x].begin(), pref[x].end(), make_pair(r, 0ll)) - pref[x].begin() - 1; if (i > j) return 0; return pref[x][j].ss - (i > 0 ? pref[x][i - 1].ss : 0ll); }; for (auto [y, w]: a[0]) dp[0].emplace_back(y - 1, 0); ll ans = 0; for (int x = 1; x < n; x++) { // cout << '\t' << x << endl; for (int i = 0; i < a[x].size(); i++) { a[x][i].ff--; ll mx = 0; for (int j = 0; j < a[x - 1].size(); j++) { if (dp[x - 1][j].ff > a[x][i].ff) continue; mx = max(mx, dp[x - 1][j].ss + get(x - 1, dp[x - 1][j].ff + 1, a[x][i].ff)); if (j < dp2[x - 1].size()) mx = max(mx, dp2[x - 1][j].ss); } dp[x].emplace_back(a[x][i].ff, mx); // cout << i << ' ' << a[x][i].ff << ' ' << dp[x].back().ss << endl; dp2[x].emplace_back(a[x][i].ff, dp[x - 1].back().ss + get(x, a[x][i].ff + 1, n)); ans = max(ans, max(dp[x].back().ss, dp2[x].back().ss)); a[x][i].ff++; } } return ans; } // g++ -o fish -O2 fish.cpp grader.cpp -std=c++17 && .\fish < input.txt > output.txt

Compilation message (stderr)

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int i = 0; i < a[x].size(); i++) {
      |                         ~~^~~~~~~~~~~~~
fish.cpp:37:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             for (int j = 0; j < a[x - 1].size(); j++) {
      |                             ~~^~~~~~~~~~~~~~~~~
fish.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                 if (j < dp2[x - 1].size()) mx = max(mx, dp2[x - 1][j].ss);
      |                     ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...