結果

問題 No.107 モンスター
ユーザー kosakkunkosakkun
提出日時 2017-01-11 12:26:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,499 bytes
コンパイル時間 1,284 ms
コンパイル使用メモリ 92,176 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 07:03:04
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int dp[1<<16];

int main(){
    
    int N; cin>>N;
    vector<int> D(N);
    REP(i,N)cin>>D[i];
    
    REP(i,1<<16)dp[i]=-1e9;
    dp[0] = 100;
    
    for (int i=0; i<(1<<N); i++ ) {
        for (int j=0; j<N; j++ ) {
            int mask = (1<<j);
            if( i&mask ) {
                if( dp[i^mask]+D[j] >0 ) {
                    dp[i] = max(dp[i],dp[i^mask]+D[j]);
                }
            }
        }
        int cnt=1;
        for (int j=0; j<N; j++ ){
            if ( (i>>j)&1 ) {
                if( D[j]<0 ) cnt++;
            }
        }
        dp[i] = min(dp[i],cnt*100);
    }
    
    if(dp[(1<<N)-1]<=0)cout<<0<<endl;
    else cout<<dp[(1<<N)-1]<<endl;
    
    return 0;
}
0