Submission #628423

# Submission time Handle Problem Language Result Execution time Memory
628423 2022-08-13T11:47:52 Z kingmoshe Catfish Farm (IOI22_fish) C++17
3 / 100
85 ms 12880 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;
    }
    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[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;
}


/*int main() {

}*/

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 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++) {
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2388 KB Output is correct
2 Correct 28 ms 3004 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 85 ms 8412 KB Output is correct
6 Correct 81 ms 8416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 48 ms 12880 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2388 KB Output is correct
2 Correct 28 ms 3004 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 85 ms 8412 KB Output is correct
6 Correct 81 ms 8416 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Runtime error 48 ms 12880 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -