結果

問題 No.393 2本の竹
コンテスト
ユーザー h_noson
提出日時 2016-07-15 10:47:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,243 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 69,072 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-15 01:10:42
合計ジャッジ時間 2,412 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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