結果

問題 No.2982 Logic Battle
ユーザー 👑 rin204
提出日時 2024-12-07 00:11:12
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 528 ms / 2,000 ms
コード長 2,706 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 104,288 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-07 00:11:26
合計ジャッジ時間 12,250 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<vector<long long>> dp(3, vector<long long>(n + 1, -(1LL << 60)));
    dp[0][0] = dp[1][0] = dp[2][0] = 0;

    for (int t = 0; t < n; ++t) {
        vector<long long> A(3);
        for (int i = 0; i < 3; ++i) {
            cin >> A[i];
        }

        vector<vector<long long>> ndp(3, vector<long long>(n + 1, -(1LL << 60)));

        for (int i1 = 0; i1 < 3; ++i1) {
            for (int i2 = 0; i2 < 3; ++i2) {
                if (i1 == i2) continue;

                for (int j = 0; j < n; ++j) {
                    long long nj = j + A[i2];
                    long long nv = dp[i1][j];
                    if (nj > n) {
                        nv += (n - t) * (nj - n);
                        nj = n;
                    }

                    nv += nj;
                    nj          = max(nj - 1, 0LL);
                    ndp[i2][nj] = max(ndp[i2][nj], nv);
                }
            }
        }
        dp = ndp;
    }

    long long result = -(1LL << 60);
    for (const auto &row : dp) {
        result = max(result, *max_element(row.begin(), row.end()));
    }

    cout << result << endl;

    return 0;
}

// #include <algorithm>
// #include <climits>
// #include <iostream>
// #include <vector>
//
// using namespace std;
//
// int main() {
//     int n;
//     cin >> n;
//
//     vector<vector<long long>> dp(3, vector<long long>(n + 1, -(1LL << 60)));
//     dp[0][0] = dp[1][0] = dp[2][0] = 0;
//
//     for (int t = 0; t < n; ++t) {
//         vector<long long> A(3);
//         for (int i = 0; i < 3; ++i) {
//             cin >> A[i];
//         }
//
//         vector<vector<long long>> ndp(3, vector<long long>(n + 1, -(1LL << 60)));
//
//         for (int i1 = 0; i1 < 3; ++i1) {
//             for (int i2 = 0; i2 < 3; ++i2) {
//                 if (i1 == i2) continue;
//
//                 for (int j = 0; j < n; ++j) {
//                     long long nj = j + A[i2];
//                     long long nv = dp[i1][j];
//                     if (nj > n) {
//                         nv += (n - t) * (nj - n);
//                         nj = n;
//                     }
//
//                     nv += nj;
//                     nj          = max(nj - 1, 0LL);
//                     ndp[i2][nj] = max(ndp[i2][nj], nv);
//                 }
//             }
//         }
//         dp = ndp;
//     }
//
//     long long result = -(1LL << 60);
//     for (const auto &row : dp) {
//         result = max(result, *max_element(row.begin(), row.end()));
//     }
//
//     cout << result << endl;
//
//     return 0;
// }
0