結果

問題 No.914 Omiyage
ユーザー ateate
提出日時 2019-10-25 22:48:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,261 bytes
コンパイル時間 4,184 ms
コンパイル使用メモリ 203,040 KB
実行使用メモリ 12,124 KB
最終ジャッジ日時 2023-10-11 07:12:59
合計ジャッジ時間 8,785 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:30:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   30 | main(){
      | ^~~~

ソースコード

diff #

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
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(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

ll ans;
int n,m,k;

void dfs(ll t,int i,vector<vector<ll>>& a){
  if(k-t<0)return;
  if(i+1==n){
    chmin(ans,k-t);
    return;
  }
  for(int nx=m-1;nx>=0;--nx){
    dfs(t+a[i+1][nx],i+1,a);
  }
}

main(){

  cin>>n>>m>>k;
  auto a = make_vector<ll>(n,m);
  cin>>a;

  ans=INF;
  dfs(a[0][0],0,a);
  if(ans==INF){cout<<(-1)<<endl;return 0;}
  for(int j=m-1;j>=0;--j){
    dfs(a[0][j],0,a);
  }
  cout<<(ans==INF?-1:ans)<<endl;

}
0