結果
問題 | No.914 Omiyage |
ユーザー |
![]() |
提出日時 | 2019-10-25 21:24:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 670 bytes |
コンパイル時間 | 1,559 ms |
コンパイル使用メモリ | 175,356 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 16:21:06 |
合計ジャッジ時間 | 2,228 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for(int i = 0; i < (int)n; i++)using namespace std;using ll = long long;using P = pair<ll, ll>;int main() {int n, m, k;cin >> n >> m >> k;vector<vector<int>> a(n, vector<int>(m));rep(i, n) rep(j, m) cin >> a[i][j];vector<bool> dp(k + 1, false);dp[0] = true;rep(i, n) {vector<bool> ndp(k + 1, false);rep(j, k + 1) rep(l, m) {if(j - a[i][l] >= 0 && dp[j - a[i][l]]) ndp[j] = true;}dp = ndp;}int ans = -1;rep(i, k + 1) if(dp[i]) ans = i;if(ans == -1) cout << -1 << endl;else cout << k - ans << endl;return 0;}