Submission #892887

#TimeUsernameProblemLanguageResultExecution timeMemory
892887Trisanu_DasCatfish Farm (IOI22_fish)C++17
0 / 100
47 ms10960 KiB
#include <bits/stdc++.h> #include "fish.h" using namespace std; #define ll long long #define ff first #define ss second int n; //global var for storing N vector<pair<int, int> > fishes[100005]; //Stores the fishes in each row struct SegmentTree{ ll tree[1 << 18]; void init(){ memset(tree, 0xcf, sizeof(tree)); } void upd(int idx, int s, int e, int l, int r, ll val){ if(e < l || r < s) return; if(l <= s && e <= r){ tree[idx] = max(tree[idx], val); return; } int mid = (s + e) / 2; upd(2 * idx, s, mid, l, r, val); upd(2 * idx + 1, mid + 1, e, l, r, val); } ll qry(int idx, int s, int e, int x){ if(s == e) return tree[idx]; int mid = (s + e) / 2; if(x <= mid) return qry(2 * idx, s, mid, x); return qry(2 * idx + 1, mid + 1, e, x); } }st_up, st_down; ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){ n = N; for(int i = 0; i < M; i++) fishes[X[i] + 1].push_back({Y[i] + 1, W[i]}); ll till_now = 0; st_down.init(); for(int i = 1; i <= n; i++){ sort(fishes[i].begin(), fishes[i].end()); for(auto [j, w] : fishes[i]) st_up.upd(1, 0, n + 1, j + 1, n + 1, st_up.qry(1, 0, n + 1, j) + w); reverse(fishes[i].begin(), fishes[i].end()); for(auto [j, w] : fishes[i]) st_down.upd(1, 0, n + 1, 0, j - 1, st_down.qry(1, 0, n + 1, j) + w); ll u_res = st_up.qry(1, 0, n + 1, n + 1), d_res = st_down.qry(1, 0, n + 1, 0); st_up.upd(1, 0, n + 1, 0, n + 1, d_res); st_down.upd(1, 0, n + 1, 0, n + 1, till_now); till_now = max(u_res, d_res); } return st_down.qry(1, 0, n + 1, 0); }
#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...