답안 #625487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625487 2022-08-10T13:31:31 Z I_love_Hoang_Yen 메기 농장 (IOI22_fish) C++17
3 / 100
98 ms 19768 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long
struct Fish {
    int col, row;
    int weight;
};
bool operator < (const Fish& a, const Fish& b) {
    if (a.col != b.col) return a.col < b.col;
    return a.row < b.row;
}

// fishes are on even columns -> build piers on odd columns
// & catch all fishes
int sub1(const std::vector<Fish>& fishes) {
    int res = 0;
    for (const auto& fish : fishes) {
        res += fish.weight;
    }
    return res;
}

// fishes are on first 2 columns
int sub2(int n, const std::vector<Fish>& fishes) {
    std::vector<int> zeroes(n);  // prefix sum of fish weights at column == 0
    std::vector<int> ones(n);    // prefix sum of fish weights at column == 1
    for (const auto& fish : fishes) {
        if (fish.col == 0) zeroes[fish.row] += fish.weight;
        if (fish.col == 1) ones[fish.row] += fish.weight;
    }

    std::partial_sum(zeroes.begin(), zeroes.end(), zeroes.begin());
    std::partial_sum(ones.begin(), ones.end(), ones.begin());

    int res = ones.back();  // init: only catch fishes at column == 1
    for (int i = 0; i < n; ++i) {
        // build pier until at column 1, row 0-i
        res = std::max(res, zeroes[i] + ones.back() - ones[i]);
    }
    return res;
}

int solve(int n, const std::vector<Fish>& fishes) {
    if (std::all_of(
                fishes.begin(), fishes.end(),
                [] (const Fish& f) { return f.col % 2 == 0; })) {
        return sub1(fishes);
    }
    return sub1(fishes);
}

#undef int
long long max_weights(
        int n, int nFish,
        std::vector<int> x,
        std::vector<int> y,
        std::vector<int> w) {
    std::vector<Fish> fishes;
    for (int i = 0; i < nFish; ++i) {
        fishes.push_back({x[i], y[i], w[i]});
    }
    return solve(n, fishes);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 5320 KB Output is correct
2 Correct 28 ms 5832 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 98 ms 19768 KB Output is correct
6 Correct 93 ms 19676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 47 ms 10368 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80901044391025'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 15 ms 3240 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722970331638'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '6066'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '6066'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '6066'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 15 ms 3240 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722970331638'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 5320 KB Output is correct
2 Correct 28 ms 5832 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 98 ms 19768 KB Output is correct
6 Correct 93 ms 19676 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 47 ms 10368 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80901044391025'
9 Halted 0 ms 0 KB -