結果

問題 No.914 Omiyage
ユーザー jjjjjjjtgpptmjjjjjjjjjtgpptmjj
提出日時 2019-10-25 21:39:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,177 bytes
コンパイル時間 1,685 ms
コンパイル使用メモリ 169,952 KB
実行使用メモリ 813,428 KB
最終ジャッジ日時 2023-09-30 07:12:59
合計ジャッジ時間 6,596 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;
typedef long long ll;

const int MOD = 1e9+7;
const int INF = 1e9;
int A[15][15];
int N,M,K;
vector<int> ans;
void dfs(int pre,int sum){
    if(sum>K)return;
    if(pre == M){
        ans.push_back(sum);
        return;
    }
    for(int j = 0; j < M; ++j){
        dfs(pre+1,sum+A[pre+1][j]);
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin>>N>>M>>K;
    rep(i,N)rep(j,M){
        cin>>A[i][j];
    }
    rep(i,M){
        dfs(0,A[0][i]);
    }
    //print(ans);
    sort(all(ans));
    if(ans[0]>K){
        cout<<-1<<endl;
        return 0;
    }
    int res = INF;
    rep(i,int(ans.size())){
        if(K>=ans[i]){
            res = min(res,max(0,K-ans[i]));
        }
    }
    cout<<res<<endl;
}
0