結果
| 問題 |
No.37 遊園地のアトラクション
|
| コンテスト | |
| ユーザー |
ふっぴー
|
| 提出日時 | 2017-09-05 22:37:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,441 bytes |
| コンパイル時間 | 1,835 ms |
| コンパイル使用メモリ | 173,044 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-10 13:25:36 |
| 合計ジャッジ時間 | 2,638 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int main() {
int t;
cin >> t;
int n, i, j;
cin >> n;
vi c(n), v(n);
for (i = 0; i < n; i++) {
cin >> c[i];
}
for (i = 0; i < n; i++) {
cin >> v[i];
}
vll dp(n+1, vl(t + 1,-1));
dp[0][0] = 0;
for (i = 0; i < n; i++) {
for (j = t; j >=0 ; j--) {
if (dp[i][j] != -1) {
dp[i + 1][j] = max(dp[i+1][j],dp[i][j]);
for (int k = v[i], cnt = 1; k > 0; k /= 2, cnt++) {
if (j + c[i] * cnt <= t) {
dp[i + 1][j + c[i] * cnt] = max(dp[i + 1][j + c[i] * cnt], dp[i + 1][j + c[i] * (cnt - 1)] + k);
}
else {
break;
}
}
}
}
}
ll ans=0;
//DEBUG_VEC(dp[0]); DEBUG_VEC(dp[1]); DEBUG_VEC(dp[2]); DEBUG_VEC(dp[3]); DEBUG_VEC(dp[4]); DEBUG_VEC(dp[5]);
for (i = 0; i <= t; i++) {
ans = max(ans, dp[n][i]);
}
cout << ans << endl;
}
ふっぴー