結果

問題 No.393 2本の竹
ユーザー h_nosonh_noson
提出日時 2016-07-15 10:47:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,243 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 68,908 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 01:54:24
合計ジャッジ時間 2,491 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 18 ms
6,940 KB
testcase_16 AC 32 ms
6,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 5 ms
6,940 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:23: warning: ‘mask’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |         rep (i,m) if (!(mask&1<<i)) rrep (j,n[1]-a[i]+1) {
      |                       ^~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)

const int INF = 1e8;
const int MOD = 1e9+7;

typedef long long ll;

ll dp[100001];

int main(void) {
    int d;
    int a[60];
    cin >> d;
    while (d--) {
        int i, j, k, m;
        int n[2];
        cin >> n[0] >> n[1] >> m;
        if (n[0] < n[1]) swap(n[0],n[1]);
        rep (i,m) cin >> a[i];
        sort(a,a+m);
        rep (i,n[0]+1) dp[i] = 0;
        rep (i,m) rrep (j,n[0]-a[i]+1) {
            if (__builtin_popcountll(dp[j+a[i]]) <= __builtin_popcountll(dp[j]) + 1) {
                dp[j+a[i]] = dp[j] | 1 << i;
            }
        }
        int ma = 0, mask;
        rep (i,n[0]+1) {
            int x = __builtin_popcountll(dp[i]);
            if (ma <= x) {
                ma = x;
                mask = dp[i];
            }
        }
        rep (i,n[1]+1) dp[i] = 0;
        rep (i,m) if (!(mask&1<<i)) rrep (j,n[1]-a[i]+1) {
            dp[j+a[i]] = max(dp[j+a[i]],dp[j]+1);
        }
        cout << dp[n[1]] + ma << endl;
    }
    return 0;
}
0