結果

問題 No.37 遊園地のアトラクション
ユーザー tkmst201
提出日時 2017-05-22 21:15:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,043 bytes
コンパイル時間 1,204 ms
コンパイル使用メモリ 159,856 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-10 13:17:57
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         REP(i, N) scanf("%d", c + i);
      |                   ~~~~~^~~~~~~~~~~~~
main.cpp:31:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         REP(i, N) scanf("%d", v + i);
      |                   ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int T, N;
int c[15], v[15];
int dp[16][10001];

int main() {
	cin >> T >> N;
	REP(i, N) scanf("%d", c + i);
	REP(i, N) scanf("%d", v + i);
	
	REP(i, N) {
		int vnow = v[i];
		while (vnow) {
			for (int j = T - c[i]; j >= 0; j--) chmax(dp[i][j + c[i]], dp[i][j] + vnow);
			vnow /= 2;
		}
		REP(j, T + 1) chmax(dp[i + 1][j], dp[i][j]);
	}
	
	int ans = 0;
	REP(i, T + 1) chmax(ans, dp[N][i]);
	cout << ans << endl;
	
	return 0;
}
0