| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 753592 | armand | Catfish Farm (IOI22_fish) | C++17 | 101 ms | 7768 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 "fish.h"
#include <algorithm>
using namespace std;
long long solve3(int n, int m, vector<int>& x, vector<int>& y, vector<int>& w)
{
const int N = 1000001;
int* a = new int [N];
long long ** b = new long long * [2];
int i;
for (i = 0; i < 2; i++)
b[i] = new long long[N];
for (i = 0; i < N; i++)
a[i] = 0;
for (i = 0; i < m; i++)
a[x[i]] = w[i];
b[0][0] = 0; b[1][0] = 0;
b[0][1] = a[0]; b[1][1] = a[1];
for (i = 2; i < n; i++) {
b[0][i] = max(b[1][i - 2] + a[i - 1], b[0][i - 2] + a[i - 1]);
b[1][i] = max(b[0][i - 1] + a[i], b[1][i - 1]);
}
return max(b[0][n - 1], b[1][n - 1]);
}
long long solve2(int n, int m, vector<int>& x, vector<int>& y, vector<int>& w)
{
int i, j;
long long suma = 0, sumb = 0, ans, ans2=0, tmp;
vector< pair<int, int> > a, b;
for (i = 0; i < m; i++)
if (x[i] == 0) {
suma += w[i];
a.push_back(make_pair(y[i], w[i]));
}
else {
sumb += w[i];
b.push_back(make_pair(y[i], w[i]));
}
ans = suma > sumb ? suma : sumb;
if (n > 2) {
sort(a.begin(), a.end());
sort(b.begin(), b.end());
ans2 = sumb;
i = 0; j = 0;
tmp = ans2;
for (j = 0; j < b.size(); j++) {
while (i < a.size() && a[i].first < b[j].first) {
tmp += a[i].second;
i++;
}
if (tmp > ans2) ans2 = tmp;
if(i<a.size() && a[i].first == b[j].first)
tmp += a[i++].second;
tmp -= b[j].second;
if (tmp > ans2)
ans2 = tmp;
}
return ans > ans2 ? ans : ans2;
}
return ans;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W)
{
int i;
bool flag2 = true, flag3=true;
long long ans = 0;
for (i = 0; i < M; i++) {
if (X[i] > 1)
flag2 = false;
if (Y[i] > 0)
flag3 = false;
}
if (flag2)
return solve2(N, M, X, Y, W);
if (flag3)
return solve3(N, M, X, Y, W);
for (i = 0; i < W.size(); i++)
ans += W[i];
return ans;
}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... | ||||
