結果

問題 No.914 Omiyage
ユーザー saxofone111saxofone111
提出日時 2021-03-30 22:56:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 208,516 KB
実行使用メモリ 5,500 KB
最終ジャッジ日時 2023-08-20 19:20:33
合計ジャッジ時間 3,537 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

vector<llvec> A;
ll N, M, K;


llvec v;
llvec v1;
llvec v2;

void dfs(ll n){
  if(n==N/2){
    ll s = 0;
    rep(i, n){
      s += A[i][v[i]];
    }
    v1.push_back(s);
    return;
  }else{
    rep(i, M){
      v.push_back(i);
      dfs(n+1);
      v.pop_back();
    }
    return;
  }
}


void dfs2(ll n){
  if(n==N-N/2){
    ll s = 0;
    rep(i, n){
      s += A[i+N/2][v[i]];
    }
    v2.push_back(s);
    return;
  }else{
    rep(i, M){
      v.push_back(i);
      dfs2(n+1);
      v.pop_back();
    }
    return;
  }
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> M >> K;
  A = vector<llvec>(N, llvec(M));
  rep(i, N){
    rep(j, M){
      cin >> A[i][j];
    }
  }

  dfs(0);
  dfs2(0);
  //v1.push_back(0);
  //v2.push_back(0);
  
  sort(ALL(v1));
  sort(ALL(v2));
  ll ans = 1e18;
  for(auto iv: v1){
    if(iv>K)break;
    auto iter = upper_bound(ALL(v2), K - iv) - v2.begin();
    if(iter!=0){
      ans = min(ans, K - (v2[iter-1] + iv));
    }
  }
  if(ans>1e16)ans = -1;
  cout << ans << endl;

  return 0;
}
0