結果
| 問題 | No.1947 質より種類数 |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2022-05-26 16:34:35 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 1,003 bytes |
| 記録 | |
| コンパイル時間 | 7,487 ms |
| コンパイル使用メモリ | 148,864 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-09 01:25:12 |
| 合計ジャッジ時間 | 8,820 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 37 |
コンパイルメッセージ
main.cpp:20:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
20 | ll VS[N];
| ^
main.cpp:20:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:6: note: declared here
17 | ll N, V, C;
| ^
main.cpp:21:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
21 | ll WS[N];
| ^
main.cpp:21:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:6: note: declared here
17 | ll N, V, C;
| ^
main.cpp:27:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
27 | ll dp[V + 1];
| ^~~~~
main.cpp:27:9: note: read of non-const variable 'V' is not allowed in a constant expression
main.cpp:17:9: note: declared here
17 | ll N, V, C;
| ^
3 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll N, V, C;
cin >> N >> V >> C;
ll VS[N];
ll WS[N];
for (int i = 0; i < N; ++i) {
cin >> VS[i] >> WS[i];
}
ll dp[V + 1];
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (int i = 0; i < N; ++i) {
for (int v = V - VS[i]; v >= 0; --v) {
if (dp[v] < 0) continue;
ll nv = v + VS[i];
ll nw = dp[v] + WS[i] + C;
dp[nv] = max(dp[nv], nw);
}
}
for (int i = 0; i < N; ++i) {
for (int v = 0; v <= V - VS[i]; ++v) {
if (dp[v] < 0) continue;
ll nv = v + VS[i];
ll nw = dp[v] + WS[i];
dp[nv] = max(dp[nv], nw);
}
}
ll ans = 0;
for (int v = 0; v <= V; ++v) {
if (dp[v] < 0) continue;
ans = max(ans, dp[v]);
}
cout << ans << endl;
return 0;
}
siman