結果

問題 No.914 Omiyage
ユーザー oevloevl
提出日時 2020-04-19 18:19:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 209,984 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 19:31:22
合計ジャッジ時間 3,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,248 KB
testcase_01 AC 10 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 13 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int INF = 1 << 30;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    int X = (N + 1) / 2, Y = N / 2; assert(X + Y == N);
    vector<vector<int>> A(X, vector<int>(M));
    vector<vector<int>> B(Y, vector<int>(M));
    for(int i = 0; i < X; ++i) {
        for(int j = 0; j < M; ++j) cin >> A[i][j];
    }
    for(int i = 0; i < Y; ++i) {
        for(int j = 0; j < M; ++j) cin >> B[i][j];
    }
    map<int, int> ma, ma2;
    auto rec = [&](auto &&rec, int now, int d) -> void {
        if(d == X) { ma[now]++; return; }
        for(int i = 0; i < M; ++i) rec(rec, now + A[d][i], d + 1);
    }; rec(rec, 0, 0);

    auto rec2 = [&](auto &&rec2, int now, int d) -> void {
        if(d == Y) { ma2[now]++; return; }
        for(int i = 0; i < M; ++i) rec2(rec2, now + B[d][i], d + 1);
    }; rec2(rec2, 0, 0);

    int ans = INF;
    for(auto &[v, key] : ma) {
        for(int a = 0; a < K; ++a) {
            if(ma2[K - a - v]) ans = min(ans, a);
        }
    }
    cout << ans << '\n';
    return 0;
}
0