結果
| 問題 | No.37 遊園地のアトラクション | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-06-07 05:55:07 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 461 bytes | 
| コンパイル時間 | 2,447 ms | 
| コンパイル使用メモリ | 193,984 KB | 
| 最終ジャッジ日時 | 2025-01-10 23:38:51 | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 27 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int W,n; scanf("%d%d",&W,&n);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,n) scanf("%d",&w[i]);
      |                  ~~~~~^~~~~~~~~~~~
main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         rep(i,n) scanf("%d",&v[i]);
      |                  ~~~~~^~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int main(){
	int W,n; scanf("%d%d",&W,&n);
	vector<int> w(n),v(n);
	rep(i,n) scanf("%d",&w[i]);
	rep(i,n) scanf("%d",&v[i]);
	vector<int> dp(W+1,-INF);
	dp[0]=0;
	rep(i,n){
		int val=v[i];
		while(val>0){
			for(int x=W;x>=w[i];x--) dp[x]=max(dp[x],dp[x-w[i]]+val);
			val/=2;
		}
	}
	printf("%d\n",*max_element(dp.begin(),dp.end()));
	return 0;
}
            
            
            
        