답안 #628311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628311 2022-08-13T09:50:44 Z TheQuantiX 메기 농장 (IOI22_fish) C++17
14 / 100
782 ms 2097152 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> > v(n, vector<ll>(n));
    int mx = 0;
    for (int i = 0; i < m; i++) {
        v[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] += v[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] += v[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();
//}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 782 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 782 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 744 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 1 ms 340 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 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 6 ms 3668 KB Output is correct
11 Correct 3 ms 1748 KB Output is correct
12 Correct 5 ms 3540 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 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 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 6 ms 3668 KB Output is correct
11 Correct 3 ms 1748 KB Output is correct
12 Correct 5 ms 3540 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '299', found: '199'
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 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 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 6 ms 3668 KB Output is correct
11 Correct 3 ms 1748 KB Output is correct
12 Correct 5 ms 3540 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '299', found: '199'
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 744 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 782 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -