結果

問題 No.393 2本の竹
ユーザー 0w10w1
提出日時 2016-12-10 19:10:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 1,000 ms
コード長 1,569 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 169,212 KB
実行使用メモリ 24,924 KB
最終ジャッジ日時 2023-08-19 10:27:26
合計ジャッジ時間 3,486 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
19,752 KB
testcase_01 AC 2 ms
5,680 KB
testcase_02 AC 5 ms
21,864 KB
testcase_03 AC 3 ms
13,616 KB
testcase_04 AC 3 ms
11,708 KB
testcase_05 AC 3 ms
9,628 KB
testcase_06 AC 2 ms
7,464 KB
testcase_07 AC 4 ms
13,748 KB
testcase_08 AC 6 ms
19,920 KB
testcase_09 AC 65 ms
24,872 KB
testcase_10 AC 14 ms
9,736 KB
testcase_11 AC 24 ms
13,712 KB
testcase_12 AC 27 ms
17,864 KB
testcase_13 AC 19 ms
15,780 KB
testcase_14 AC 8 ms
13,696 KB
testcase_15 AC 10 ms
22,900 KB
testcase_16 AC 15 ms
24,120 KB
testcase_17 AC 4 ms
15,660 KB
testcase_18 AC 3 ms
11,684 KB
testcase_19 AC 2 ms
5,532 KB
testcase_20 AC 3 ms
7,472 KB
testcase_21 AC 5 ms
17,716 KB
testcase_22 AC 32 ms
11,596 KB
testcase_23 AC 16 ms
11,792 KB
testcase_24 AC 4 ms
9,612 KB
testcase_25 AC 2 ms
7,540 KB
testcase_26 AC 3 ms
7,592 KB
testcase_27 AC 51 ms
24,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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 dp[ 60 + 1 ][ 100000 + 1 ];

void init(){
  int T; cin >> T;
  for( int kase = 1; kase <= T; ++kase ){
    int N1, N2; cin >> N1 >> N2;
    if( not ( N1 <= N2 ) )
      swap( N1, N2 );
    int M; cin >> M;
    vi A( M );
    for( int i = 0; i < M; ++i )
      cin >> A[ i ];
    sort( A.begin(), A.end() );
    dp[ 0 ][ 0 ] = kase;
    for( int i = 0; i < M; ++i )
      for( int j = N1; j >= 0; --j )
        if( dp[ i ][ j ] == kase ){
          dp[ i + 1 ][ j ] = kase;
          if( j + A[ i ] <= N1 )
            dp[ i + 1 ][ j + A[ i ] ] = kase;
        }
    int ans = 0;
    for( int i = 1, s = 0; i <= M; ++i ){
      s += A[ i - 1 ];
      int max_taken = 0;
      for( int j = 1; j <= N1; ++j )
        if( dp[ i ][ j ] == kase )
          max_taken = j;
      if( s - max_taken <= N2 )
        ans = i;
    }
    cout << ans << endl;  
  }
}

void preprocess(){

}

void solve(){

}

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