답안 #1005322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005322 2024-06-22T10:22:06 Z overwatch9 메기 농장 (IOI22_fish) C++17
9 / 100
152 ms 139604 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 + 5;
ll dp[maxn][11][11];
bool ready[maxn][11][11];
ll cost(int i, int h1, int h2, int h3) {
    if (i == 1)
        return 0;
    if (max(h1, h3) <= h2 || (int)fish[i-1].size() == 1)
        return 0;
    int mx = max(h1, h3);
    pair <int, ll> tp = {h2+1, 0};
    int it = lower_bound(fish[i-1].begin(), fish[i-1].end(), tp) - fish[i-1].begin();
    tp.first = mx;
    tp.second = 1e18;
    int it2 = upper_bound(fish[i-1].begin(), fish[i-1].end(), tp) - fish[i-1].begin();
    it2--;
    // if (it == it2)
    //     return 0;
    if (it == 0)
        return pfx[i-1][it2];
    return pfx[i-1][it2] - pfx[i-1][it-1];
}
int get_id(int x, int i) {
    if (x == 10 || i == 0)
        return 0;
    if (x == 0 || x == 1 || x == 2)
        return fish[i-1][x].first;
    if (x <= 5)
        return fish[i][x - 3].first;
    return fish[i+1][x - 6].first;
}
ll solve(int i, int h1, int h2) {
    if (i == n+1) {
        return cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), 0);
    }
    if (ready[i][h1][h2])
        return dp[i][h1][h2];
    ll ans = solve(i+1, h2, 10) + cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), 0);
    int id = 0;
    if (i-1 >= 1) {
        if ((int)fish[i-1].size() == 2)
            ans = max(ans, solve(i+1, h2, 1) + cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), fish[i-1][1].first));
        if ((int)fish[i-1].size() == 3)
            ans = max(ans, solve(i+1, h2, 2) + cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), fish[i-1][2].first));
    }
    for (auto j : fish[i]) {
        if ((int)fish[i].size() == 2) {
            ans = max(ans, solve(i+1, h2, 4) + cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), fish[i][1].first));
        }
        if ((int)fish[i].size() == 3) {
            ans = max(ans, solve(i+1, h2, 5) + cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), fish[i][2].first));
        }
    }
    if (i+1 <= n) {
        if ((int)fish[i+1].size() == 2)
            ans = max(ans, solve(i+1, h2, 7) + cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), fish[i+1][1].first));
        if ((int)fish[i+1].size() == 3) {
            ans = max(ans, solve(i+1, h2, 8) + cost(i, get_id(h1, max(i-2, 0)), get_id(h2, i-1), fish[i+1][2].first));
        }
    }
    ready[i][h1][h2] = true;
    dp[i][h1][h2] = ans;
    return ans;
}
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 = 0; 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);
        pfx[i][0] = 0;
        for (int j = 1; j < (int)fish[i].size(); j++)
            pfx[i][j] = pfx[i][j-1] + fish[i][j].second;
    }
    return solve(1, 10, 10);
}
// 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';
// }

Compilation message

fish.cpp: In function 'll solve(int, int, int)':
fish.cpp:53:15: warning: variable 'j' set but not used [-Wunused-but-set-variable]
   53 |     for (auto j : fish[i]) {
      |               ^
fish.cpp:46:9: warning: unused variable 'id' [-Wunused-variable]
   46 |     int id = 0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 126924 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Incorrect 65 ms 130680 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 135000 KB Output is correct
2 Correct 32 ms 135100 KB Output is correct
3 Correct 85 ms 125520 KB Output is correct
4 Correct 71 ms 136508 KB Output is correct
5 Correct 136 ms 139604 KB Output is correct
6 Correct 130 ms 139600 KB Output is correct
7 Correct 147 ms 139600 KB Output is correct
8 Correct 138 ms 139604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '0'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '0'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '0'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 135000 KB Output is correct
2 Correct 32 ms 135100 KB Output is correct
3 Correct 85 ms 125520 KB Output is correct
4 Correct 71 ms 136508 KB Output is correct
5 Correct 136 ms 139604 KB Output is correct
6 Correct 130 ms 139600 KB Output is correct
7 Correct 147 ms 139600 KB Output is correct
8 Correct 138 ms 139604 KB Output is correct
9 Correct 152 ms 139600 KB Output is correct
10 Incorrect 92 ms 75596 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '36240209738286'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 126924 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '0'
2 Halted 0 ms 0 KB -