結果

問題 No.2329 Nafmo、イカサマをする
ユーザー ozraruozraru
提出日時 2023-05-28 15:22:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 2,368 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 208,084 KB
実行使用メモリ 11,676 KB
最終ジャッジ日時 2023-08-27 12:01:44
合計ジャッジ時間 4,015 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 82 ms
7,308 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 283 ms
11,676 KB
testcase_42 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <numeric>
// #include <atcoder/modint>

using namespace std;
// using namespace atcoder;

// using mint = modint998244353;

#define i64 int_fast64_t

const i64 INF = INT64_MAX;

const i64 ERR = INT64_MIN;

const i64 MOD = 998244353;

// 切り上げ
i64 ceil_devide(i64 x, i64 y) {
    return (x + y - 1) / y;
}

// 切り捨て
i64 floor_devide(i64 x, i64 y) {
    return x / y;
}

i64 sum_linear(i64 n) {
    return n * (n+1) / 2;
}

int main()
{
    i64 n,m,k;
    cin >> n >> m >> k;

    vector<i64> a(n+1);

    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    a.at(n) = 0;

    set<i64> merged;
    
    if (k >= 2) {
        for (size_t i1 = 0; i1 < n+1; i1++)
        {
            if (k >= 4) {
                for (size_t i2 = 0; i2 < n+1; i2++)
                {
                    if (k >= 6) {
                        for (size_t i3 = 0; i3 < n+1; i3++)
                        {
                            merged.insert(a.at(i1) + a.at(i2) + a.at(i3));
                        }
                    } else {
                        merged.insert(a.at(i1) + a.at(i2));
                    }
                }
            } else {
                merged.insert(a.at(i1));
            }
        }
    } else {
        merged.insert(0);
    }

    i64 best = 0;

    if (k % 2 == 0) {
        auto pos1 = merged.begin();
        auto pos2 = merged.end();
        pos2--;
        while (pos1 != pos2)
        {
            if (*pos1 + *pos2 > m) {
                pos2--;
            } else {
                best = max(best, *pos1 + *pos2);
                pos1++;
            }
        }
        if (*pos1 + *pos2 <= m) {
            best = max(best, *pos1 + *pos2);
        }
    } else {
        for (size_t i = 0; i < n+1; i++)
        {
            auto pos1 = merged.begin();
            auto pos2 = merged.end();
            pos2--;

            while (pos1 != pos2)
            {
                if (*pos1 + *pos2 + a.at(i) > m) {
                    pos2--;
                } else {
                    best = max(best, *pos1 + *pos2 + a.at(i));
                    pos1++;
                }
            }
            if (*pos1 + *pos2 + a.at(i) <= m) {
                best = max(best, *pos1 + *pos2 + a.at(i));
            }
        }
    }
    
    cout << best << endl;

    return 0;
}
0