結果
問題 | No.1037 exhausted |
ユーザー | minato |
提出日時 | 2020-05-23 01:43:35 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,643 bytes |
コンパイル時間 | 3,736 ms |
コンパイル使用メモリ | 234,888 KB |
実行使用メモリ | 34,688 KB |
最終ジャッジ日時 | 2024-04-15 22:38:32 |
合計ジャッジ時間 | 4,962 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 37 ms
34,560 KB |
testcase_13 | AC | 36 ms
34,304 KB |
testcase_14 | AC | 36 ms
34,304 KB |
testcase_15 | AC | 36 ms
34,560 KB |
testcase_16 | AC | 37 ms
34,304 KB |
testcase_17 | AC | 37 ms
34,560 KB |
testcase_18 | AC | 38 ms
34,560 KB |
testcase_19 | AC | 37 ms
34,432 KB |
testcase_20 | AC | 32 ms
34,432 KB |
testcase_21 | AC | 31 ms
34,688 KB |
testcase_22 | AC | 28 ms
34,688 KB |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<long long, long long>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; //constexpr long long MOD = 998244353LL; template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; } template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; } void print() { cout << "\n"; } template <class T, class... Args> void print(const T &x, const Args &... args) { cout << x << " "; print(args...); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,V,L; cin >> N >> V >> L; vector<int> x(N+1),v(N+1),w(N+1); rep(i,N) cin >> x[i] >> v[i] >> w[i]; x[N] = L; vector<vector<ll>> dp(N+2, vector<ll>(V+1,1e18)); dp[0][V] = 0; int cur = 0; rep(i,N+1) { int d = x[i] - cur; rep(j,V+1) { if (j < d or dp[i][j]==1e18) continue; chmin(dp[i+1][j-d],dp[i][j]); int nv = min(V,j-d+v[i]); chmin(dp[i+1][nv],dp[i][j]+w[i]); } cur = x[i]; } ll ans = 1e18; rep(i,V+1) chmin(ans,dp[N+1][i]); cout << (ans==1e18 ? -1 : ans) << ln; }