結果

問題 No.393 2本の竹
ユーザー しらっ亭しらっ亭
提出日時 2016-07-12 13:40:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,999 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 176,136 KB
実行使用メモリ 24,632 KB
最終ジャッジ日時 2023-08-05 03:19:04
合計ジャッジ時間 4,322 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 69 ms
9,900 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 77 ms
8,220 KB
testcase_14 AC 38 ms
6,920 KB
testcase_15 AC 44 ms
18,800 KB
testcase_16 AC 84 ms
19,204 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 70 ms
9,760 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;
typedef long long ll;

template<class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

int solve(int N1, int N2, int M, vi &A) {
  vvi dp(M+1, vi(N1+1, -1));
  dp[0][0] = 0;
  rep(i, M) rep(j, N1+1) if (dp[i][j] >= 0) {
    dp[i+1][j] = dp[i][j];
    if (j + A[i] <= N1) amax(dp[i+1][j + A[i]], dp[i][j] + 1);
  }

  /*
  rep(i,M+1) {
    _p("dp[%d]:", i);
    rep(j,SZ(dp[i])) _p(" %d", dp[i][j]);
    _p("\n");
  }
  */

  int ma = 0;
  rep(i, N1+1) {
    if (dp[M][i] >= dp[M][ma]) {
      ma = i;
    }
  }

  //cout<<"ma: "<<ma<<endl;
  set<int> used;
  rrep(i, 1, M+1) {
    if (ma - A[i-1] >= 0 && dp[i][ma] == dp[i-1][ma - A[i-1]] + 1) {
      used.insert(i-1);
      ma -= A[i-1];
    }
  }
  //forr(u, used) _p("u: %d\n", u);

  vi dp2(N2+1, -1);
  dp2[0] = 0;
  rep(i, M) if (used.count(i) == 0) rrep(j, N2) if (dp2[j] >= 0) {
    if (j + A[i] <= N2) amax(dp2[j + A[i]], dp2[j] + 1);
  }
  //rep(i,SZ(dp2)) cout<<"dp2["<<i<<"]: "<<dp2[i]<<endl;

  return *max_element(ALL(dp2)) + SZ(used);
}

void Main() {
  int N1, N2, M;
  scanf("%d%d%d", &N1, &N2, &M);
  vi A(M);
  rep(i, M) scanf("%d", &A[i]);
  _p("%d\n", max(solve(N1, N2, M, A), solve(N2, N1, M, A)));
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) Main();
  return 0;
}
0