結果

問題 No.2542 Yokan for Two
ユーザー AlgeotAlgeot
提出日時 2023-11-25 11:38:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,448 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 210,124 KB
実行使用メモリ 813,944 KB
最終ジャッジ日時 2023-11-25 11:38:10
合計ジャッジ時間 7,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 542 ms
364,336 KB
testcase_04 AC 394 ms
215,936 KB
testcase_05 MLE -
testcase_06 AC 47 ms
31,976 KB
testcase_07 MLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
    int L, N;
    cin >> L >> N;
    vector<int> X(N + 2);
    X[0] = 0;
    X[N + 1] = L;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        X[i + 1] = x;
    }
    vector<int> A;
    for (int i = 0; i < N + 1; i++)
    {
        A.push_back(X[i + 1] - X[i]);
    }
    N = A.size();
    int M = 2 * L + 10;
    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(M, vector<int>(2)));
    dp[0][L][0] = 1;
    for (int i = 0; i < N; i++)
    {
        int a = A[i];
        for (int j = 0; j < M; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                if (dp[i][j][k] == 0)
                {
                    continue;
                }
                if (k == 0)
                {
                    dp[i + 1][j + a][k] = 1;
                    if (i > 0)
                    {
                        dp[i + 1][j - a][1 - k] = 1;
                    }
                }
                else
                {
                    dp[i + 1][j - a][k] = 1;
                    if (i > 0)
                    {
                        dp[i + 1][j + a][1 - k] = 1;
                    }
                }
            }
        }
    }
    int ans = pow(10, 9);
    for (int j = 0; j < M; j++)
    {
        if (dp[N][j][1] == 1)
        {
            ans = min(ans, abs(j - L));
        }
    }
    cout << ans << endl;
}
0