結果

問題 No.914 Omiyage
ユーザー huka_hukahuka_huka
提出日時 2021-09-24 19:40:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 148,580 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 20:18:39
合計ジャッジ時間 2,778 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# ifndef ONLINE_JUDGE
# define _GLIBCXX_DEBUG
# endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
# define rep(i, n) for(int i = 0; i < (int)(n); i++)
# define all(v) v.begin(), v.end()

int main(){
  constexpr char endl = '\n';
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  //input();
  int N, M, K;cin >> N >> M >> K;
  vvi cost(N, vi(M));
  for(auto &&e : cost)  for(auto &&ee : e)  cin >> ee;
  //solve();
  vvi dp(N+1, vi(K+1));
  //dp[i+1][j]:=i番目の国まで行ったとき、j円かかるか
  dp[0][0] = 1;
  bool ok;
  rep(i, N){
    ok = false;
    for(int j = 0; j <=K; ++j){
      rep(m, M){
        if(dp[i][j] && j+cost[i][m] <= K){
          dp[i+1][j+cost[i][m]] = 1;
          ok = true;
        }
      }
    }
    if(!ok)  break;
  }
  //output();
  if(!ok)  cout << -1 << endl;
  else{
    for(int j = K; 0 <= j; --j){
      if(dp[N][j]){
        cout << K-j << endl;
        break;
      }
    }
  }
}
0