結果

問題 No.914 Omiyage
ユーザー m-44m-44
提出日時 2019-10-26 21:35:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 614 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 164,180 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-12 20:08:31
合計ジャッジ時間 2,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int main() {
  int n, m, k;
  cin>>n>>m>>k;
  int a[n][m];
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) cin>>a[i][j];
  }
  int dp[501];
  for (int i=0; i<501; i++) dp[i] = 0;
  for (int i=0; i<m; i++) dp[a[0][i]] = 1;
  for (int i=1; i<n; i++) {
    for (int j=0; j<501; j++) {
      for (int k=0; k<m; k++) {
        if (j - a[i][k] >= 0 && dp[j-a[i][k]] == i) {
          dp[j] = i + 1;
          break;
        }
      }
    }
  }
  for (int i=k; i>=0; i--) {
    if (dp[i] == n) {
      cout<<k - i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}
0