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 <iostream>
#include <vector>
bool is_even(std::vector<int> X) {
for (int i = 0; i < X.size(); i++) {
if (X[i] % 2 == 1) {
return false;
}
}
return true;
}
bool is_only_start(std::vector<int> X) {
for (int i = 0; i < X.size(); i++) {
if (X[i] > 1) {
return false;
}
}
return true;
}
long long solve_only_start(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
if (N == 2) {
long long res0 = 0;
long long res1 = 0;
for (int i = 0; i < M; i++) {
if (X[i] == 0) {
res0 += W[i];
}
else {
res1 += W[i];
}
}
if (res0 > res1) {
return res0;
}
return res1;
}
long long cur_res = 0;
for (int i = 0; i < M; i++) {
if (X[i] == 1) {
cur_res += W[i];
}
}
std::vector<int> values(N);
for (int i = 0; i < M; i++) {
if (X[i] == 0) {
values[Y[i]] += W[i];
}
else {
values[Y[i]] -= W[i];
}
}
for (int i = 1; i < N; i++) {
values[i] += values[i - 1];
}
long long best_res = cur_res;
for (int i = 0; i < N; i++) {
if (values[i] + cur_res > best_res) {
best_res = values[i] + cur_res;
}
}
return best_res;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
if (is_even(X)) {
long long res = 0;
for (int i = 0; i < W.size(); i++) {
res += W[i];
}
return res;
}
else if (is_only_start(X)) {
return solve_only_start(N, M, X, Y, W);
}
return 0;
}
/*int main() {
int n = 10;
int m = 5;
std::vector<int> x{ 0, 1, 1, 1, 1 };
std::vector<int> y{ 0, 0, 1, 2, 3 };
std::vector<int> w{ 4, 1, 1, 1, 1 };
std::cout << max_weights(n, m, x, y, w) << std::endl;
}//*/
Compilation message (stderr)
fish.cpp: In function 'bool is_even(std::vector<int>)':
fish.cpp:7:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | for (int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
fish.cpp: In function 'bool is_only_start(std::vector<int>)':
fish.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:73:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < W.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |