Submission #1105472

#TimeUsernameProblemLanguageResultExecution timeMemory
1105472VinhLuuCatfish Farm (IOI22_fish)C++17
52 / 100
1140 ms724412 KiB
#include <bits/stdc++.h> #define ll long long #include "fish.h" using namespace std; const int N = 3e3 + 5; const ll oo = -1e16; int n, m; ll a[N][N], f[3][N][N], g[3][N][N]; void vin(ll &x,ll y){ x = max(x, y); } long long max_weights(int _N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { n = _N; m = M; for(int i = 1; i <= m; i ++){ int x = X[i - 1] + 1, y = Y[i - 1] + 1, c = W[i - 1]; a[x][y] += c; } // for(int i = 1; i <= n; i ++){ // for(int j = 1; j <= n; j ++) cerr << a[i][j] << " "; // cerr << "\n"; // } for(int i = 0; i <= n; i ++){ for(int j = 0; j <= n + 1; j ++){ a[i][j] += (j > 0 ? a[i][j - 1] : 0); for(int k = 0; k <= 1; k ++){ f[k][i][j] = g[k][i][j] = oo; } } } f[0][0][0] = f[1][0][0] = 0; g[1][0][0] = 0; for(int i = 1; i <= n; i ++){ g[1][0][i] = g[1][0][i - 1]; } // cerr << " g\n"; ll ans = 0; for(int i = 1; i <= n; i ++){ ll ret = oo; for(int j = 0; j <= n; j ++) ret = max({ret, f[0][i - 1][j], f[1][i - 1][j]}); f[0][i][0] = f[1][i][0] = ret; for(int j = 0; j <= n; j ++){ vin(f[1][i][j], 0); vin(f[0][i][j], 0); if(j > 0) vin(f[1][i][j], a[i - 1][j] + g[1][i - 1][j - 1]); vin(f[0][i][j], g[0][i - 1][j + 1] - a[i][j]); // cerr << i << " " << j << " " << f[0][i][j] << " " << f[1][i][j] << " h\n"; vin(ans, max(f[1][i][j], f[0][i][j])); } for(int j = 0; j <= n; j ++){ g[1][i][j] = f[1][i][j] - a[i][j]; if(j > 0) vin(g[1][i][j], g[1][i][j - 1]); // cerr << " " << 1 << " " << i << " " << j << " " << g[1][i][j] << " uuu\n"; } for(int j = n; j >= 0; j --){ g[0][i][j] = max(f[0][i][j], f[1][i][j]) + a[i + 1][j]; if(j < n) vin(g[0][i][j], g[0][i][j + 1]); // cerr << " " << 0 << " " << i << " " << j << " " << g[0][i][j] <<" ooo\n"; } } return ans; } //#define LOCAL #ifdef LOCAL int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } int _N, M; assert(2 == scanf("%d %d", &_N, &M)); std::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; } /* 5 4 0 2 5 1 1 2 4 4 1 3 3 3 */ #endif // LOCAL
#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...