結果

問題 No.1037 exhausted
ユーザー jupiro
提出日時 2020-04-24 21:55:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,845 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 130,380 KB
最終ジャッジ日時 2025-01-09 23:39:05
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |         ll N, V, L; scanf("%lld %lld %lld", &N, &V, &L);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:53:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |         for (int i = 0; i < N; i++) scanf("%lld %lld %lld", &x[i], &v[i], &w[i]);
      |                                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#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;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
ll N, V, L; scanf("%lld %lld %lld", &N, &V, &L);
vector<vector<ll>> dp(N + 1, vector<ll>(V + 1, INF));
dp[0][V] = 0;
vector<ll> x(N), v(N), w(N);
for (int i = 0; i < N; i++) scanf("%lld %lld %lld", &x[i], &v[i], &w[i]);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= V; j++) {
if (dp[i][j] == INF) continue;
if (i == 0) {
if (x[i] > j) continue;
chmin(dp[i + 1][j - x[i]], dp[i][j]);
chmin(dp[i + 1][min(V, j - x[i] + v[i])], dp[i][j] + w[i]);
}
else {
if (x[i] - x[i - 1]> j) continue;
chmin(dp[i + 1][j - x[i] + x[i -1]], dp[i][j]);
chmin(dp[i + 1][min(V, j - x[i] + x[i - 1] + v[i])], dp[i][j] + w[i]);
}
}
}
ll res = INF;
for (int j = 0; j <= V; j++) {
ll len = L - x.back();
if (len > j) continue;
chmin(res, dp[N][j]);
}
if (res == INF) puts("-1");
else cout << res << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0