Submission #825556

#TimeUsernameProblemLanguageResultExecution timeMemory
825556becaidoCatfish Farm (IOI22_fish)C++17
0 / 100
100 ms23396 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "fish.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const ll INF = 1e18; const int SIZE = 1e5 + 5; int n; vector<pair<int, int>> v[SIZE]; ll ans, zero[2], fzero[2], all[2]; vector<pair<int, ll>> inc[2], dek[2]; inline void chmax(ll &x, const ll &y) { x = max(x, y); } ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { n = N; FOR (i, 0, M - 1) { X[i]++, Y[i]++; v[X[i]].pb(Y[i], W[i]); } fzero[0] = all[0] = -INF; FOR (i, 1, n) { int f = i & 1; sort(v[i].begin(), v[i].end()); zero[f] = fzero[f] = all[f] = -INF; inc[f].clear(), dek[f].clear(); ll mx = zero[!f], sum = 0; int pos = 0; for (auto [j, x] : v[i - 1]) { while (pos < inc[!f].size() && inc[!f][pos].F < j) { mx = max(mx, inc[!f][pos].S - sum); pos++; } sum += x; inc[f].pb(j, sum + mx); } while (pos < inc[!f].size() && inc[!f][pos].F < n) { mx = max(mx, inc[!f][pos].S - sum); pos++; } chmax(all[f], sum + mx); mx = all[!f], sum = 0, pos = (int) dek[!f].size() - 1; for (auto [j, x] : v[i]) sum += x; for (auto it = v[i].rbegin(); it != v[i].rend(); it++) { auto [j, x] = *it; while (pos >= 0 && dek[!f][pos].F > j) { mx = max(mx, dek[!f][pos].S + sum); pos--; } dek[f].pb(j, mx - sum); sum -= x; } while (pos >= 0 && dek[!f][pos].F > 0) { mx = max(mx, dek[!f][pos].S + sum); pos--; } chmax(fzero[f], mx - sum); reverse(dek[f].begin(), dek[f].end()); chmax(zero[f], zero[!f]); chmax(zero[f], fzero[!f]); chmax(all[f], fzero[!f]); chmax(all[f], all[!f]); } int f = n & 1; ll ans = 0; chmax(ans, zero[f]); chmax(ans, fzero[f]); chmax(ans, all[f]); return ans; } /* in1 5 4 0 2 5 1 1 2 4 4 1 3 3 3 out1 8 */ #ifdef WAIMAI int main() { int N, M; assert(2 == scanf("%d %d", &N, &M)); vector<int> X(M), Y(M), W(M); for (int i = 0; i < M; ++i) { assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i])); } long long result = max_weights(N, M, X, Y, W); printf("%lld\n", result); return 0; } #endif

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:54:24: 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]
   54 |             while (pos < inc[!f].size() && inc[!f][pos].F < j) {
      |                    ~~~~^~~~~~~~~~~~~~~~
fish.cpp:61:20: 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]
   61 |         while (pos < inc[!f].size() && inc[!f][pos].F < n) {
      |                ~~~~^~~~~~~~~~~~~~~~
#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...