답안 #628430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628430 2022-08-13T11:54:20 Z kingmoshe 메기 농장 (IOI22_fish) C++17
3 / 100
91 ms 8432 KB
#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

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++) {
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2508 KB Output is correct
2 Correct 28 ms 3000 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 81 ms 8432 KB Output is correct
6 Correct 91 ms 8416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 260 KB Output is correct
2 Incorrect 49 ms 6300 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40481344848725'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2508 KB Output is correct
2 Correct 28 ms 3000 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 81 ms 8432 KB Output is correct
6 Correct 91 ms 8416 KB Output is correct
7 Correct 0 ms 260 KB Output is correct
8 Incorrect 49 ms 6300 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40481344848725'
9 Halted 0 ms 0 KB -