# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
661006 | mychecksedad | Catfish Farm (IOI22_fish) | C++17 | 86 ms | 23764 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int S = 1e5 + 100;
ll dp[S][15], a[S][2], s[S], pref[S][15];
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w){
bool case1 = 1, case2 = 1;
for(int i = 0; i < m; ++i){
if(x[i] % 2) case1 = 0;
if(x[i] > 1) case2 = 0;
}
if(case1){
ll ans = 0;
for(int i = 0; i < m; ++i) ans += w[i];
return ans;
}
if(case2){
ll ans1 = 0, ans2 = 0;
for(int i = 0; i < m; ++i){
if(x[i] == 0) ans1 += w[i];
else ans2 += w[i];
}
if(n == 2)
return max(ans1, ans2);
else{
ll best = 0, sum = 0;
int p = 0;
for(int i = 0; i <= n + 1; ++i) a[i][0] = a[i][1] = s[i] = 0;
for(int i = 0; i < m; i++) if(x[i] == 0) a[y[i]][0] = w[i]; else a[y[i]][1] = w[i];
for(int i = n; i >= 0; --i) s[i] = s[i + 1] + a[i][1];
for(int i = 0; i <= n + 1; ++i){
best = max(best, s[i] + sum);
sum += a[i][0];
}
return best;
}
}
for(int i = 0; i <= n; ++i){
for(int j = 0; j < 15; ++j) pref[i][j] = dp[i][j] = 0;
}
for(int i = 0; i < m; ++i) pref[x[i]][y[i] + 1] = w[i];
for(int i = 0; i <= n; ++i){
for(int j = 1; j < 15; ++j) pref[i][j] += pref[i][j - 1];
}
for(int i = 1; i <= n; ++i){
for(int j = 0; j < 10; ++j){
for(int k = 0; k < 10; ++k){
dp[i][j] = max(dp[i][j], dp[i - 1][k] + pref[i + 1][j] - pref[i][k] + max(0ll, pref[i - 1][j] - pref[i - 1][k]));
}
}
}
return dp[n][0];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |