結果

問題 No.914 Omiyage
ユーザー MiccMicc
提出日時 2019-10-26 12:03:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 176,756 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 21:17:31
合計ジャッジ時間 2,331 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:65:13: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   65 |       cout<<ans<<endl;
      |             ^~~
main.cpp:58:11: note: 'ans' was declared here
   58 |       int ans;
      |           ^~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,k;
  cin>>n>>m>>k;
  vector<vector<int>> a(n+1,vector<int>(m+1));
  rep(i,n)rep(j,m) cin>>a[i+1][j+1];
  vector<vector<bool>> dp(n+1,vector<bool>(k+10,false));
  dp[0][k]=true;
  rep(i,n)rep(j,k+1){
    FOR(l,1,m+1){
      if(j+a[i+1][l]<=k) dp[i+1][j]=dp[i+1][j]||dp[i][j+a[i+1][l]];
    }
  }
  FOR(i,1,n+1){
    bool flag=false;
    rep(j,k+1){
      if(dp[i][j]){
        flag=true;
        break;
      }
    }
    if(!flag){
      cout<<-1<<endl;
      return 0;
    }
    if(i==n){
      int ans;
      rep(j,k+1){
        if(dp[i][j]){
          ans=j;
          break;
        }
      }
      cout<<ans<<endl;
    }
  }
}
0