結果

問題 No.2232 Miser's Gift
ユーザー 👑 p-adicp-adic
提出日時 2023-02-21 15:04:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 4,375 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 78,936 KB
実行使用メモリ 4,396 KB
最終ジャッジ日時 2023-09-29 13:00:46
合計ジャッジ時間 6,368 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 11 ms
4,384 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 10 ms
4,376 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 AC 12 ms
4,380 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 12 ms
4,396 KB
testcase_28 AC 11 ms
4,380 KB
testcase_29 AC 11 ms
4,380 KB
testcase_30 AC 12 ms
4,376 KB
testcase_31 AC 12 ms
4,380 KB
testcase_32 AC 11 ms
4,376 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 11 ms
4,380 KB
testcase_35 AC 11 ms
4,376 KB
testcase_36 AC 11 ms
4,380 KB
testcase_37 AC 11 ms
4,388 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ( "O3" )
#pragma GCC optimize( "unroll-loops" )
#pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <cassert>
using namespace std;

#define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type
#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr )
#define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE
#define CIN( LL , A ) LL A; cin >> A
#define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
#define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX )
#define GETLINE( S ) string S; getline( cin , S ); int VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S = 0; int VARIABLE_FOR_SIZE_FOR_STOI_ ## S = S.size()
#define GETLINE_SEPARATE( S , SEPARATOR ) string S; getline( cin , S , SEPARATOR )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES )
#define QUIT return 0
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n"

// 入力フォーマットチェック用
// 余分な改行を許さない
#define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin )
// #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; getline( cin , VARIABLE_FOR_CHECK_REDUNDANT_INPUT ); assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin )
// |N| <= BOUNDを満たすNをSから構築
#define STOI( S , N , BOUND ) TYPE_OF( BOUND ) N = 0; { bool VARIABLE_FOR_POSITIVITY_FOR_STOI = true; assert( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ); if( S.substr( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S , 1 ) == "-" ){ VARIABLE_FOR_POSITIVITY_FOR_STOI = false; VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S ++; assert( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ); } assert( S.substr( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S , 1 ) != " " ); string VARIABLE_FOR_LETTER_FOR_STOI{}; int VARIABLE_FOR_DIGIT_FOR_STOI{}; while( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ? ( VARIABLE_FOR_LETTER_FOR_STOI = S.substr( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S , 1 ) ) != " " : false ){ VARIABLE_FOR_DIGIT_FOR_STOI = stoi( VARIABLE_FOR_LETTER_FOR_STOI ); assert( N < BOUND / 10 ? true : N == BOUND / 10 && VARIABLE_FOR_DIGIT_FOR_STOI <= BOUND % 10 ); N = N * 10 + VARIABLE_FOR_DIGIT_FOR_STOI; VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S ++; } if( ! VARIABLE_FOR_POSITIVITY_FOR_STOI ){ N *= -1; } if( VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_STOI_FOR_ ## S ){ VARIABLE_FOR_INDEX_FOR_STOI_FOR_ ## S ++; } }
// 1行で入力される変数の個数が適切か確認(半角空白の個数+1を調べる)
#define COUNT_VARIABLE( S , VARIABLE_NUMBER ) { int size = S.size(); int count = 0; for( int i = 0 ; i < size ; i++ ){ if( S.substr( i , 1 ) == " " ){ count++; } } assert( count + 1 == VARIABLE_NUMBER ); }

int main()
{
  UNTIE;
  CEXPR( int , bound_N , 100 );
  CIN_ASSERT( N , 1 , bound_N );
  CEXPR( int , bound_W , 100000 );
  CIN_ASSERT( W , 1 , bound_W );
  CEXPR( int , bound_V , 10000000 );
  int val[2][bound_W + 1] = {};
  int i_prev = 0;
  int i_curr = 1;
  int w_prev = W;
  REPEAT( N ){
    int ( &val_prev )[bound_W + 1] = val[i_prev];
    int ( &val_curr )[bound_W + 1] = val[i_curr];
    CIN_ASSERT( wi , 1 , bound_W );
    CIN_ASSERT( vi , 1 , bound_V );
    FOR( w , w_prev , wi ){
      val_curr[w] = val_prev[w];
    }
    FOREQ( w , wi , W ){
      val_curr[w] = max( val_prev[w] , val_prev[w - wi] + vi );
    }
    w_prev = wi;
    swap( i_prev , i_curr );
  }
  CHECK_REDUNDANT_INPUT;
  int ( &val_last )[bound_W + 1] = val[i_prev];
  int val_max = 0;
  FOREQ( w , 1 , W ){
    int& val_last_w = val_last[w];
    if( val_max < val_last_w ){
      val_max = val_last_w;
    } else {
      val_last_w = val_max;
    }
  }
  int val_last_W_plus = val_last[W] + 1;
  FOREQ( X , 1 , W ){
    COUT( val_last_W_plus - val_last[W - X] );
  }
  QUIT;
}
0