結果
問題 |
No.247 線形計画問題もどき
|
ユーザー |
|
提出日時 | 2020-07-14 01:09:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,801 bytes |
コンパイル時間 | 1,163 ms |
コンパイル使用メモリ | 126,420 KB |
最終ジャッジ日時 | 2025-01-11 20:23:53 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 TLE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:54:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 54 | int C; scanf("%d", &C); | ~~~~~^~~~~~~~~~ main.cpp:55:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 55 | int n; scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:56:56: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 56 | vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; int dp[2][100001]; void init(int x) { for (int i = 0; i <= 100000; i++) dp[x][i] = inf; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int C; scanf("%d", &C); int n; scanf("%d", &n); vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); init(0), init(1); int cur = 0; int nxt = 1; dp[0][0] = 0; for (int i = 0; i < n; i++) { init(nxt); for (int j = 0; j <= C; j++) { if (dp[cur][j] == -inf) continue; for (int k = 0; k <= C; k++) { if (a[i] * k + j > C) break; chmin(dp[nxt][a[i] * k + j], dp[cur][j] + k); } } swap(cur, nxt); } int res = dp[cur][C]; if (res == inf) res = -1; cout << res << endl; return 0; }