結果
問題 |
No.914 Omiyage
|
ユーザー |
|
提出日時 | 2021-08-31 07:02:07 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 962 bytes |
コンパイル時間 | 5,142 ms |
コンパイル使用メモリ | 144,740 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-24 22:31:09 |
合計ジャッジ時間 | 4,340 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <iostream> #include <utility> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <functional> #include <iomanip> #include <map> #include <set> #include <queue> using namespace std; using ll = long long int; #define chmax(x,y) x = (x > (y)) ? x : (x = (y)); #define chmin(x,y) x = (x < (y)) ? x : (x = (y)); int main(int argc, char const *argv[]) { int N,M,K; cin >> N >> M >> K; vector<vector<int>> A(N,vector<int>(M)); for(auto &a : A) { for(auto &e : a) { cin >> e; } } vector<vector<int>> dp(N+1,vector<int>(K+1)); dp[0][0] = 1; for(int i=0;i<N;++i) { for(int j=0;j<K;++j) { if(dp[i][j]) { for(auto &a : A[i]) { if(j + a <= K)dp[i+1][j+a] = 1; } } } } int id = 0; for(int i=1;i<=K;++i) { if(dp[N][i])chmax(id,i); } if(id == 0)std::cout << -1 << std::endl; else std::cout << K-id << std::endl; }