結果

問題 No.37 遊園地のアトラクション
ユーザー 0w10w1
提出日時 2016-12-05 15:57:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,535 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 167,496 KB
実行使用メモリ 10,664 KB
最終ジャッジ日時 2024-04-18 19:53:34
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,496 KB
testcase_01 AC 4 ms
10,656 KB
testcase_02 AC 7 ms
10,624 KB
testcase_03 AC 5 ms
10,512 KB
testcase_04 AC 6 ms
10,464 KB
testcase_05 AC 7 ms
10,464 KB
testcase_06 AC 4 ms
10,624 KB
testcase_07 AC 12 ms
10,564 KB
testcase_08 AC 4 ms
10,496 KB
testcase_09 AC 3 ms
10,592 KB
testcase_10 AC 15 ms
10,664 KB
testcase_11 AC 9 ms
10,624 KB
testcase_12 AC 5 ms
10,624 KB
testcase_13 AC 4 ms
10,624 KB
testcase_14 AC 5 ms
10,656 KB
testcase_15 AC 7 ms
10,600 KB
testcase_16 AC 8 ms
10,636 KB
testcase_17 AC 5 ms
10,428 KB
testcase_18 AC 14 ms
10,604 KB
testcase_19 AC 4 ms
10,624 KB
testcase_20 AC 7 ms
10,624 KB
testcase_21 AC 4 ms
10,496 KB
testcase_22 AC 5 ms
10,496 KB
testcase_23 AC 4 ms
10,584 KB
testcase_24 AC 4 ms
10,424 KB
testcase_25 AC 3 ms
10,552 KB
testcase_26 AC 3 ms
10,624 KB
testcase_27 AC 8 ms
10,600 KB
testcase_28 AC 5 ms
10,624 KB
testcase_29 AC 6 ms
10,452 KB
testcase_30 AC 3 ms
10,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int T;
int N;
vi C;
vi V;

void init(){
  cin >> T;
  cin >> N;
  C = V = vi( N );
  for( int i = 0; i < N; ++i )
    cin >> C[ i ];
  for( int i = 0; i < N; ++i )
    cin >> V[ i ];
}

int dp[ 15 + 1 ][ 10000 + 1 ][ 10 + 1 ];

void preprocess(){
  memset( dp, -1, sizeof( dp ) );
  dp[ 0 ][ T ][ 0 ] = 0;
  for( int i = 0; i < N; ++i )
    for( int t = T; t >= 0; --t )
      for( int j = 0; j <= 10; ++j )
        if( dp[ i ][ t ][ j ] != -1 ){
          if( j + 1 <= 10 and t - C[ i ] >= 0 )
            upmax( dp[ i ][ t - C[ i ] ][ j + 1 ], dp[ i ][ t ][ j ] + ( int ) ( V[ i ] / pow( 2, j ) ) );
          upmax( dp[ i + 1 ][ t ][ 0 ], dp[ i ][ t ][ j ] );
        }
}

void solve(){
  int ans = 0;
  for( int t = 0; t <= 10000; ++t )
    for( int j = 0; j <= 10; ++j )
      upmax( ans, dp[ N ][ t ][ j ] );
  cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0