結果
問題 |
No.247 線形計画問題もどき
|
ユーザー |
![]() |
提出日時 | 2015-07-18 00:02:02 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,894 bytes |
コンパイル時間 | 829 ms |
コンパイル使用メモリ | 101,444 KB |
実行使用メモリ | 20,000 KB |
最終ジャッジ日時 | 2024-07-08 09:48:05 |
合計ジャッジ時間 | 4,338 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 5 |
other | AC * 2 TLE * 1 -- * 20 |
ソースコード
#include <algorithm> #include <array> #include <sstream> #include <cstdio> #include <functional> #include <cstdlib> #include <cctype> #include <ostream> #include<complex> #include <cmath> #include <iostream> #include <stack> #include <fstream> #include <queue> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <bitset> #include <iomanip> #include <string> #include <vector> #include <string> using namespace std; #define OB (bitset<32>) #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define ALLOF(c) begin(), (c),end() typedef long long ll; #define PI acos(-1) #define EPS 0.000000001 #define MOD 1000000007 int main() { int c; int n; int a[100]; cin >>c >> n; fill(a,a+100,-1);//invalid error on sort rep(i,n) { cin >> a[i]; } map<int,int> dp[10001]; dp[0].insert(make_pair(0,0)); sort(a,a+100,greater<int>()); rep(i,n) { for (auto ittr = dp[i].begin(); ittr != dp[i].end() ; ittr++) { for (int k = 0;; k++) { int x = ittr->first; int y = ittr->second; if ((x + k*a[i]) > c) { break; } auto next = dp[i+1].find(x + k*a[i]); if (next == dp[i+1].end()) { dp[i+1].insert(make_pair(x +k*a[i],y+k)); continue; } if ( next->second > y+k) { dp[i+1].erase(next->first); dp[i+1].insert(make_pair(x+k*a[i],y+k)); } } } } if (dp[n].find(c) != dp[n].end()) { int ans = dp[n].find(c)->second; cout << ans <<endl; return 0; } cout << "-1" << endl; return 0; }