Submission #628420

# Submission time Handle Problem Language Result Execution time Memory
628420 2022-08-13T11:46:22 Z kingmoshe Catfish Farm (IOI22_fish) C++17
Compilation error
0 ms 0 KB
#include "fish.h"

#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;
    }
    ll 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[i] += W[i];
        }
        else {
            values[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;
}

Compilation message

fish.cpp: In function 'bool is_even(std::vector<int>)':
fish.cpp:6:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for (int i = 0; i < X.size(); i++) {
      |                     ~~^~~~~~~~~~
fish.cpp: In function 'bool is_only_start(std::vector<int>)':
fish.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i < X.size(); i++) {
      |                     ~~^~~~~~~~~~
fish.cpp: In function 'long long int solve_only_start(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:41:5: error: 'll' was not declared in this scope
   41 |     ll cur_res = 0;
      |     ^~
fish.cpp:44:13: error: 'cur_res' was not declared in this scope
   44 |             cur_res += W[i];
      |             ^~~~~~~
fish.cpp:59:26: error: 'cur_res' was not declared in this scope
   59 |     long long best_res = cur_res;
      |                          ^~~~~~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < W.size(); i++) {
      |                         ~~^~~~~~~~~~