답안 #699046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699046 2023-02-15T12:48:48 Z dxz05 메기 농장 (IOI22_fish) C++17
0 / 100
735 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define MP make_pair

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    vector<vector<pair<int, int>>> fish(N);
    vector<vector<ll>> sum(N);
    for (int i = 0; i < M; i++){
        fish[X[i]].emplace_back(Y[i] + 1, W[i]);
    }

    for (int i = 0; i < N; i++){
        sort(fish[i].begin(), fish[i].end());
        int k = (int)fish[i].size();
        sum[i].resize(k);
        for (int j = 0; j < k; j++){
            sum[i][j] = fish[i][j].second;
            if (j > 0) sum[i][j] += sum[i][j - 1];
        }
    }

    function<ll(int, int, int)> get_sum = [&](int i, int l, int r){ // sum of fish with X = i, l <= Y <= r
        int pl = lower_bound(fish[i].begin(), fish[i].end(), MP(l, 0)) - fish[i].begin();
        int pr = lower_bound(fish[i].begin(), fish[i].end(), MP(r + 1, 0)) - fish[i].begin() - 1;
        if (pl > pr) return 0ll;
        return sum[i][pr] - (pl > 0 ? sum[i][pl - 1] : 0ll);
    };

    vector<vector<ll>> dp(N, vector<ll>(N + 1, 0));
    for (int i = 1; i < N; i++){
        for (int l = 0; l <= N; l++){
            for (int j = 0; j <= N; j++){
                dp[i][l] = max(dp[i][l], dp[i - 1][j] + get_sum(i - 1, j + 1, l));
            }
            for (int j = 0; j <= N; j++){
                if (i >= 2) dp[i][l] = max(dp[i][l], dp[i - 2][j] + get_sum(i - 1, 1, l));
            }
        }
    }

    ll res = 0;
    for (int l = 0; l <= N; l++){
        res = max(res, dp[N - 1][l]);
    }

    for (int l = 0; l <= N; l++){
        res = max(res, dp[N - 2][l] + get_sum(N - 1, 1, l));
    }

    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 716 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 735 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 712 ms 2097152 KB Execution killed with signal 9
2 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 712 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 716 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -