結果

問題 No.107 モンスター
ユーザー GOTKAKO
提出日時 2025-07-03 16:35:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 982 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 201,840 KB
実行使用メモリ 17,112 KB
最終ジャッジ日時 2025-07-03 16:35:32
合計ジャッジ時間 3,696 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<int> D(N);
    for(auto &d : D) cin >> d;
    
    int n2 = 1<<N;
    vector<bitset<1701>> dp(n2); 
    vector<bitset<1701>> mask(18);
    for(int i=1; i<18; i++) for(int k=0; k<=i*100; k++) mask.at(i).set(k); 
    dp.at(0).set(100);

    for(int i=0; i<n2; i++){
        int maxh = 1;
        for(int k=0; k<N; k++) if((i&(1<<k)) && D.at(k) < 0) maxh += 1;
        if((dp.at(i)&(~mask.at(maxh))).count() > 0) dp.at(i).set(maxh*100);
        dp.at(i) &= mask.at(maxh);
        dp.at(i).reset(0);
        for(int k=0; k<N; k++){
            if(i&(1<<k)) continue;
            int d = D.at(k);
            if(d < 0) dp.at(i+(1<<k)) |= dp.at(i)>>(-d);
            else dp.at(i+(1<<k)) |= dp.at(i)<<d;
        }
    }

    int answer = 0;
    for(int i=0; i<=1700; i++) if(dp.back().test(i)) answer = i; 
    cout << answer << endl;
}
0