結果

問題 No.45 回転寿司
ユーザー heabiheabi
提出日時 2020-11-21 05:14:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 5,000 ms
コード長 1,873 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 170,456 KB
実行使用メモリ 399,372 KB
最終ジャッジ日時 2023-09-30 21:36:03
合計ジャッジ時間 10,999 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 202 ms
172,756 KB
testcase_01 AC 283 ms
240,968 KB
testcase_02 AC 436 ms
332,212 KB
testcase_03 AC 451 ms
360,624 KB
testcase_04 AC 313 ms
256,184 KB
testcase_05 AC 59 ms
52,420 KB
testcase_06 AC 259 ms
213,468 KB
testcase_07 AC 398 ms
328,520 KB
testcase_08 AC 134 ms
115,580 KB
testcase_09 AC 422 ms
344,464 KB
testcase_10 AC 217 ms
179,356 KB
testcase_11 AC 127 ms
105,808 KB
testcase_12 AC 416 ms
339,852 KB
testcase_13 AC 53 ms
48,200 KB
testcase_14 AC 37 ms
33,616 KB
testcase_15 AC 236 ms
195,448 KB
testcase_16 AC 159 ms
130,496 KB
testcase_17 AC 210 ms
170,428 KB
testcase_18 AC 165 ms
135,652 KB
testcase_19 AC 362 ms
294,968 KB
testcase_20 AC 35 ms
31,512 KB
testcase_21 AC 50 ms
44,500 KB
testcase_22 AC 8 ms
8,920 KB
testcase_23 AC 7 ms
8,920 KB
testcase_24 AC 8 ms
10,184 KB
testcase_25 AC 6 ms
7,740 KB
testcase_26 AC 237 ms
191,336 KB
testcase_27 AC 363 ms
295,892 KB
testcase_28 AC 256 ms
207,332 KB
testcase_29 AC 333 ms
272,932 KB
testcase_30 AC 343 ms
282,048 KB
testcase_31 AC 6 ms
8,600 KB
testcase_32 AC 6 ms
8,164 KB
testcase_33 AC 507 ms
399,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;  // 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void pt_vvll(vvll v) {
    ll vs = v.size(), vs0 = v[0].size();
    rep(i, vs) {
        rep(j, vs0) {
            cout << v[i][j];

            if (j != vs0 - 1)
                cout << " ";
            else
                cout << "\n";
        }
    }
}
void pt_vll(vll v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];
        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;
    vll v(N);
    rep(i, N) cin >> v[i];

    vvll dp(N + 10, vll(5e4 + 10));
    dp[0][v[0]] = 1;
    if (N >= 2) dp[1][v[1]] = 1;
    rep(i, N) {
        rep(j, 5e4 + 10) {
            if (i + 3 < N && j + v[i] < 5e4 + 10 && dp[i][j])
                dp[i + 3][j + v[i + 3]] = 1;
            if (i + 2 < N && j + v[i] < 5e4 + 10 && dp[i][j])
                dp[i + 2][j + v[i + 2]] = 1;
        }
    }

    ll ans = 0;
    rep(i, N + 10) rep(j, 5e4 + 10) if (dp[i][j]) chmax(ans, j);
    cout << ans << "\n";
    return 0;
}
0