結果

問題 No.393 2本の竹
ユーザー tnakao0123tnakao0123
提出日時 2016-07-17 17:41:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 1,453 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 88,408 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 21:28:29
合計ジャッジ時間 1,791 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 5 ms
6,940 KB
testcase_08 AC 7 ms
6,944 KB
testcase_09 AC 37 ms
6,940 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 17 ms
6,944 KB
testcase_12 AC 20 ms
6,944 KB
testcase_13 AC 12 ms
6,940 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 5 ms
6,940 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 24 ms
6,940 KB
testcase_23 AC 10 ms
6,940 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 33 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 393.cc: No.393 2本の竹 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 60;

/* typedef */

/* global variables */

int as[MAX_M], dp[2][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int tn;
  cin >> tn;
  while (tn--) {
    int n0, n1, m;
    cin >> n0 >> n1 >> m;

    for (int i = 0; i < m; i++) cin >> as[i];
    sort(as, as + m);

    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    int cur = 0, nxt = 1, asum = 0;

    for (int i = 0; i < m; i++) {
      bool cont = false;
      memset(dp[nxt], -1, sizeof(dp[nxt]));
      
      for (int j = 0; j <= n0; j++)
	if (dp[cur][j] >= 0) {
	  int d = dp[cur][j] + 1;
	  int j0 = j + as[i];
	  if (j0 <= n0 && dp[nxt][j0] < d)
	    dp[nxt][j0] = d, cont = true;
	  int j1 = asum - j + as[i];
	  if (j1 <= n1 && dp[nxt][j] < d)
	    dp[nxt][j] = d, cont = true;
	}

      if (! cont) break;

      asum += as[i];
      cur ^= 1, nxt ^= 1;
    }

    int maxdp = 0;
    for (int i = 0; i <= n0; i++)
      if (maxdp < dp[cur][i]) maxdp = dp[cur][i];
    printf("%d\n", maxdp);
  }

  return 0;
}
0