답안 #628313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628313 2022-08-13T09:54:38 Z TheQuantiX 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll n, m, x, y, k;

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> k) {
    vector< vector<ll> > e(n, vector<ll>(n));
    int mx = 0;
    for (int i = 0; i < m; i++) {
        e[x[i]][y[i]] += k[i];
        mx = max(mx, y[i]);
    }
    mx++;
    mx++;
    if (n <= 300 && mx <= 10) {
    //    cout << "DEBUG" << endl;
        vector< vector< vector< vector<ll> > > > dp(n, vector< vector< vector<ll> > > (mx, vector< vector<ll> > (mx, vector<ll>(mx))));
        for (int i = 0; i < mx; i++) {
            for (int j = 0; j < mx; j++) {
                for (int i1 = i; i1 < j; i1++) {
    //                cout << mx << ' ' << i << ' ' << j << ' ' << i1 << endl;
                    dp[0][0][i][j] += e[0][i1];
                }
    //            cout << dp[0][0][i][j] << endl;
            }
        }
    //    cout << "DEBUG" << endl;
        ll ans = 0;
        for (int x = 1; x < n; x++) {
            for (int i = 0; i < mx; i++) {
                for (int j = 0; j < mx; j++) {
                    ll mx1 = 0;
                    for (int k = 0; k < mx; k++) {
                        mx1 = max(mx1, dp[x - 1][k][i][j]);
                    }
                    for (int k = 0; k < (x == n - 1 ? 1 : mx); k++) {
                        dp[x][i][j][k] = mx1;
    //                    if (x == 1 && i == 0 && j == 3 && k == 5) {
    //                        cout << mx1 << endl;
    //                    }
                        for (int i1 = j; i1 < max(i, k); i1++) {
                            dp[x][i][j][k] += e[x][i1];
                        }
                        if (x == n - 1) {
                            ans = max(ans, dp[x][i][j][k]);
                        }
                    }
                }
            }
        }
    //    cout << endl;
    //    cout << dp[0][0][0][3] << endl;
    //    cout << dp[1][0][3][5] << endl;
    //    cout << dp[2][3][5][0] << endl;
    //    cout << dp[3][5][0][4] << endl;
    //    cout << dp[4][0][4][0] << endl;
        return ans;
    }
    else {
        vector<ll> v(n);
        for (int i = 0; i < m; i++) {
            v[x[i]] += k[i];
        }
        vector<ll> dp1(n + 1);
        vector<ll> dp2(n + 1);
        for (int i = 1; i <= n; i++) {
            if (i != n) {
                dp2[i] = v[i - 1];
                if (i >= 2) {
                    dp2[i] = max(dp2[i], dp2[i - 2] + v[i - 1]);
                    dp2[i] = max(dp2[i], dp1[i - 2] + v[i - 1]);
                }
                if (i >= 3) {
                    dp2[i] = max(dp2[i], dp1[i - 3] + v[i - 1]);
                    dp2[i] = max(dp2[i], dp2[i - 3] + v[i - 1]);
                }
                dp2[i] = max(dp2[i], dp1[i - 1] + v[i - 1]);
            }
            if (i != 1) {
                dp1[i] = v[i - 1];
                if (i >= 3) {
                    dp1[i] = max(dp1[i], dp1[i - 3] + v[i - 1]);
                    dp1[i] = max(dp1[i], dp2[i - 3] + v[i - 1]);
                }
                dp1[i] = max(dp1[i], dp2[i - 2] + v[i - 1]);
                dp1[i] = max(dp1[i], dp1[i - 2] + v[i - 1]);
            }
        }
        return max(*max_element(dp1.begin(), dp1.end()), *max_element(dp2.begin(), dp2.end()));
    }
}

void solve() {
    cin >> n >> m;
    vector<int> x(m);
    vector<int> y(m);
    vector<int> k(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i] >> k[i];
    }
    cout << max_weights(n, m, x, y, k) << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}

Compilation message

/usr/bin/ld: /tmp/cc80qhPd.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccUOvQof.o:fish.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status