답안 #1002403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002403 2024-06-19T14:17:53 Z overwatch9 메기 농장 (IOI22_fish) C++17
0 / 100
38 ms 29912 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector <vector <pair <int, ll>>> fish;
vector <vector <ll>> pfx;
int n, m;
const int maxn = 1e5 + 1;
ll dp[maxn][2][2];
bool ready[maxn][2][2];
ll cost(int i, bool l1, bool l2, bool l3) {
    if (i-1 >= 1 && !l2 && (l1 || l3))
        return fish[i-1][1].second;
    return 0;
}
ll solve(int i, bool l1, bool l2) {
    if (i == n+1) {
        if (l1 && !l2)
            return fish[i-1][1].second;
        return 0;
    }
    if (ready[i][l1][l2])
        return dp[i][l1][l2];
    ll ans = solve(i+1, l2, false) + cost(i, l1, l2, false);
    ll ans2 = solve(i+1, l2, true) + cost(i, l1, l2, true);
    ready[i][l1][l2] = true;
    dp[i][l1][l2] = max(ans, ans2);
    return max(ans, ans2);
}
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    n = N;
    m = M;
    fish.resize(N+1);
    pfx.resize(N+1);
    for (int i = 0; i < M; i++) {
        fish[X[i] + 1].push_back({Y[i] + 1, W[i]});
    }
    // dp = vector <vector <ll>> (N+1, vector <ll> (N+1, -1));
    for (int i = 1; i <= N; i++) {
        fish[i].push_back({0, 0});
        sort(fish[i].begin(), fish[i].end());
        pfx[i].resize((int)fish[i].size() + 5, 1e18);
        for (int j = 1; j < (int)fish[i].size(); j++)
            pfx[i][j] = pfx[i][j-1] + fish[i][j].second;
    }
    return solve(1, false, false);
}
// int main() {
//     int nn, mm;
//     cin >> nn >> mm;
//     vector <int> x(mm), y(mm), w(mm);
//     for (int i = 0; i < mm; i++)
//         cin >> x[i] >> y[i] >> w[i];
//     cout << max_weights(nn, mm, x, y, w) << '\n';
// }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 29912 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '227662228'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '2', found: '50'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 27336 KB 1st lines differ - on the 1st token, expected: '10082010', found: '14415235'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '34'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '34'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '34'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 27336 KB 1st lines differ - on the 1st token, expected: '10082010', found: '14415235'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 29912 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '227662228'
2 Halted 0 ms 0 KB -