Submission #1055901

#TimeUsernameProblemLanguageResultExecution timeMemory
1055901pawnedCatfish Farm (IOI22_fish)C++17
0 / 100
672 ms2097152 KiB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; #include "fish.h" ll max_weights(int N, int M, vector<int> X_g, vector<int> Y_g, vector<int> W_g) { vector<vi> a(N, vi(N, 0)); for (int i = 0; i < M; i++) { a[X_g[i]][Y_g[i]] += W_g[i]; } /* cout<<"a: "; for (vi v : a) { for (ll x : v) cout<<x<<" "; cout<<endl; }*/ vector<vi> pfs(N, vi(N + 1, 0)); // vertical pfs for (int i = 0; i < N; i++) { pfs[i][0] = 0; for (int j = 1; j <= N; j++) { pfs[i][j] = pfs[i][j - 1] + a[i][j - 1]; } } /* cout<<"pfs: "; for (vi v : pfs) { for (ll x : v) cout<<x<<" "; cout<<endl; }*/ vector<vi> dp(N + 1, vi(N + 1, 0)); // dp[i][j]: max sum till i, exclusive; j = pier height // prefix max / sum to optimize? for (int i = 1; i <= N; i++) { dp[0][i] = -1e18; } for (int i = 1; i <= N; i++) { // a[i - 1] is empty for (int j = 0; j <= N; j++) { dp[i][0] = max(dp[i][0], dp[i - 1][j] + (pfs[i - 1][j] - pfs[i - 1][0])); } for (int j = 1; j <= N; j++) { // fill up to j // try all right filled combinations if (i == 1) { // first coln dp[i][j] = 0; } else { // i >= 2 for (int k = 0; k <= j; k++) { // left is up to k <= j for (int l = 0; l <= N; l++) { // 2x left is up to l if (l >= k) { dp[i][j] = max(dp[i][j], dp[i - 2][l]); } else { dp[i][j] = max(dp[i][j], dp[i - 2][l] + (pfs[i - 2][k] - pfs[i - 2][l])); } } } for (int k = j + 1; k <= N; k++) { // left is up to k > j dp[i][j] = max(dp[i][j], dp[i - 1][k] + (pfs[i - 1][k] - pfs[i - 1][j])); } } } } /* cout<<"dp: "<<endl; for (vi v : dp) { for (ll x : v) cout<<x<<" "; cout<<endl; }*/ ll ans = 0; for (int i = 0; i <= N; i++) { ans = max(ans, dp[N][i]); } return ans; } // can extend subtask 3 logic for polynomial soln // optimize with segtree range max if needed // if have poly soln, can get subtasks 2 and 4 right away by changing bounds
#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...