結果

問題 No.914 Omiyage
ユーザー le_panda_noirle_panda_noir
提出日時 2020-07-08 23:23:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 88,756 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 09:16:44
合計ジャッジ時間 2,199 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using vi = vector<int>;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

int N, M, K;
vector<vi> A, dp;
int dfs(int i, int k) {
  // dfs(i, k) = i番目以降で、残りk円で渡すといくら残るか?
  if (i == N)
    return k;
  if (dp[i][k] != -1)
    return dp[i][k];
  int ans = k;
  rep(j, M) {
    int a = A[i][j] - A[i][0];
    if (k >= a)
      ans = min(ans, dfs(i + 1, k - a));
  }
  return dp[i][k] = ans;
}
int main() {
  ins(N, M, K);

  A.resize(N, vi(M));
  dp.resize(N, vi(501, -1));
  int sum = 0;
  rep(i, N) {
    rep(j, M) {
      cin >> A[i][j];
    }
    all(sort, A[i]);
    sum += A[i][0];
  }
  if (sum > K) {
    cout << -1 << endl;
    return 0;
  }
  cout << dfs(0, K - sum) << endl;

  return 0;
}
0