Submission #630376

#TimeUsernameProblemLanguageResultExecution timeMemory
630376amunduzbaevCatfish Farm (IOI22_fish)C++17
35 / 100
1101 ms118352 KiB
#include "fish.h" #include "bits/stdc++.h" using namespace std; typedef long long ll; #ifndef EVAL #include "grader.cpp" #endif const int N = 3005; vector<int> id[N]; int sz[N], pre[N]; ll pref[N][N], suff[N][N], mx[N][N]; ll tmp[N][N], P[N][N]; ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) { for(int i=0;i<m;i++){ x[i]++, y[i]++; if(x[i] > 1) id[x[i] - 1].push_back(y[i]); if(x[i] < n) id[x[i] + 1].push_back(y[i]); id[x[i]].push_back(y[i]); P[x[i]][y[i]] += w[i]; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ P[i][j] += P[i][j-1]; } } for(int i=0;i<N;i++){ id[i].push_back(0); sort(id[i].begin(), id[i].end()); id[i].erase(unique(id[i].begin(), id[i].end()), id[i].end()); } sz[0] = 1; for(int i=1;i<=n;i++){ sz[i] = id[i-1].size(); for(int j_=0;j_<(int)id[i].size();j_++){ int j = id[i][j_]; int pos, p2; if(i > 1){ pos = lower_bound(id[i-2].begin(), id[i-2].end(), j) - id[i-2].begin(); p2 = upper_bound(id[i-2].begin(), id[i-2].end(), j) - id[i-2].begin(); } else { pos = 0; p2 = 1; } for(int k_ = 0; k_ < sz[i]; k_++){ int k = id[i-1][k_]; tmp[j_][k_] = 0; ll s = P[i-1][j] + P[i+1][j] - (i > 1 ? P[i][min(j, k)] : 0); if(j <= k){ tmp[j_][k_] = max(tmp[j_][k_], pref[k_][sz[i-1] - 1] + s - P[i-1][j]); } else { tmp[j_][k_] = max(tmp[j_][k_], pref[k_][pre[k_] - 1] + s - P[i-1][k]); if(pos < sz[i-1]) tmp[j_][k_] = max(tmp[j_][k_], suff[k_][pos] + s - P[i-1][j]); if(p2) tmp[j_][k_] = max(tmp[j_][k_], mx[k_][p2 - 1] + s); } } } for(int j=0;j<(int)id[i].size();j++){ pre[j] = lower_bound(id[i - 1].begin(), id[i - 1].end(), id[i][j]) - id[i - 1].begin(); for(int k=0;k<sz[i];k++){ pref[j][k] = suff[j][k] = mx[j][k] = tmp[j][k]; mx[j][k] -= P[i][id[i-1][k]]; if(k) pref[j][k] = max(pref[j][k], pref[j][k-1]); if(k > pre[j]) mx[j][k] = max(mx[j][k-1], mx[j][k]); } suff[j][sz[i]] = 0; for(int k=sz[i]-1;k>=0;k--){ suff[j][k] = max(suff[j][k+1], suff[j][k]); } pre[j] = upper_bound(id[i - 1].begin(), id[i - 1].end(), id[i][j]) - id[i - 1].begin(); } } ll res = 0; for(int i=0;i<(int)id[n].size();i++){ for(int j=0;j<sz[n];j++){ res = max(res, tmp[i][j]); } } return res; } /* 5 4 0 2 5 1 1 2 4 4 1 3 3 3 5 6 2 3 3 2 1 2 4 1 3 2 0 10 4 4 1 4 0 7 */
#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...