結果

問題 No.2329 Nafmo、イカサマをする
ユーザー ozraruozraru
提出日時 2023-05-28 14:59:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,052 bytes
コンパイル時間 2,802 ms
コンパイル使用メモリ 207,156 KB
実行使用メモリ 11,660 KB
最終ジャッジ日時 2023-08-27 11:03:59
合計ジャッジ時間 4,836 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 3 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 91 ms
7,364 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,384 KB
testcase_39 WA -
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 297 ms
11,660 KB
testcase_42 AC 3 ms
4,376 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);
    }
    
    auto pos1 = merged.begin();
    auto pos2 = merged.end();
    pos2--;

    i64 best = 0;

    if (k % 2 == 0) {
        while (pos1 != pos2)
        {
            if (*pos1 + *pos2 > m) {
                pos2--;
            } else {
                best = max(best, *pos1 + *pos2);
                pos1++;
            }
        }
    } else {
        for (size_t i = 0; i < n+1; i++)
        {
            while (pos1 != pos2)
            {
                if (*pos1 + *pos2 + a.at(i) > m) {
                    pos2--;
                } else {
                    best = max(best, *pos1 + *pos2 + a.at(i));
                    pos1++;
                }
            }
        }
    }
    
    cout << best << endl;

    return 0;
}
0