結果

問題 No.393 2本の竹
ユーザー しらっ亭しらっ亭
提出日時 2016-07-12 14:19:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,083 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 173,584 KB
実行使用メモリ 24,820 KB
最終ジャッジ日時 2024-04-23 01:50:16
合計ジャッジ時間 6,668 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 35 ms
10,368 KB
testcase_16 WA -
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

// O(M^2*N)
#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; }

void Main() {
  int N1, N2, M;
  scanf("%d%d%d", &N1, &N2, &M);
  vi A(M);
  rep(i, M) scanf("%d", &A[i]);

  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 ans = 0;
  int ma = 1e9;
  vi dp2(N2+1, -1);
  rrep(i, N1+1) {
    if (dp[M][i] != -1 && dp[M][i] < ma) {
      int x = i;
      //cout<<"x: "<<x<<endl;
      set<int> used;
      rrep(i, 1, M+1) {
        if (x - A[i-1] >= 0 && dp[i][x] == dp[i-1][x - A[i-1]] + 1) {
          used.insert(i-1);
          x -= A[i-1];
        }
      }
      //forr(u, used) _p("u: %d\n", u);
      fill(ALL(dp2), -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;
      int cand = *max_element(ALL(dp2)) + SZ(used);
      amax(ans, cand);

      ma = dp[M][i];
    }
  }

  _p("%d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) Main();
  return 0;
}
0