結果

問題 No.914 Omiyage
ユーザー uchiiiiuchiiii
提出日時 2020-07-22 22:56:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,947 bytes
コンパイル時間 3,490 ms
コンパイル使用メモリ 217,832 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 03:18:24
合計ジャッジ時間 4,693 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
const int MX = 12;
int a[MX][MX];
int n,m,k;
int ans = INF;

vector<int> v1;
vector<int> v2;

void dfs(int i, int ed, int cur, vector<int>& v) {
    if(i==ed) {
        for(int j=0; j<m; j++) {
            v.emplace_back(a[i][j]+cur);
        }
        return;
    }
    for(int j=0; j<m; j++) {
        // cout << i << " "  << j << endl;
        dfs(i+1, ed, cur+a[i][j], v);
    }
}


int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n >> m >> k;
    FOR(i,0,n-1) {
        FOR(j,0,m-1) {
            cin >> a[i][j];
        }
    }

    int mid = n/2;

    if(n > 1) {
    dfs(0, mid-1, 0, v1);
    dfs(mid, n-1, 0, v2);

    int ans = INF;
    for(auto &e: v1){
        int now = k - e;
        if(now <= 0) continue;
        auto resi = upper_bound(ALL(v2), now);
        if(resi != v2.begin()) chmin(ans, now - *(resi-1));
    }

    if(ans != INF) cout << ans << endl;
    else cout << -1 << endl;
    } else {
        FOR(i,0,m-1) v1.push_back(a[0][i]);
        auto resi = upper_bound(ALL(v1), k);
        if(resi != v1.begin()) cout << k - *(resi-1) << endl;
        else cout << -1 << endl;
    }
    return 0;
}
0