結果

問題 No.107 モンスター
ユーザー 小指が強い人小指が強い人
提出日時 2016-06-25 01:45:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,242 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 83,256 KB
実行使用メモリ 12,220 KB
最終ジャッジ日時 2023-08-23 06:54:14
合計ジャッジ時間 2,384 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 15 ms
5,468 KB
testcase_14 AC 33 ms
7,380 KB
testcase_15 AC 34 ms
7,456 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 8 ms
4,564 KB
testcase_18 AC 74 ms
11,836 KB
testcase_19 AC 74 ms
11,976 KB
testcase_20 AC 18 ms
5,368 KB
testcase_21 AC 17 ms
5,428 KB
testcase_22 AC 36 ms
7,348 KB
testcase_23 AC 81 ms
11,880 KB
testcase_24 AC 80 ms
12,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <math.h>
using namespace std;

typedef pair<int,int> pai;

int n,maxn;
int d[16];
vector<pai> dp[16];
vector<bool> vis[16];

pai solve(int i,int bit){
    if(bit==maxn){
        if(d[i]>0)
            return pai(100,0);
        else
            return pai(max(0,100+d[i]),1);
    }
    if(vis[i][bit])return dp[i][bit];
    pai res(0,0);
    for(int x=0;x<n;x++){
        int mask=1<<x;
        if((bit&mask)>0)continue;
        pai t=solve(x,bit|mask);
        if(t.first<=0)continue;
        if(d[i]<0){
            t.first+=d[i];
            t.second++;
            if(t.first>0)
                res=max(t,res);
        }
        else{
            t.first=min(t.first+d[i],(t.second+1)*100);
            res=max(t,res);
        }
    }
    vis[i][bit]=true;
    return dp[i][bit]=res;
}

int main(){
    cin>>n;
    maxn=pow(2,n)-1;
    for(int i=0;i<n;i++)cin>>d[i];
    for(int i=0;i<n;i++){
        dp[i].resize(1<<n);
        vis[i].resize(1<<n);
        for(int j=0;j<n;j++){
            dp[i][j].second=dp[i][j].first=0;
        }
    }
    int res=0;
    for(int i=0;i<n;i++)res=max(res,solve(i,1<<i).first);
    cout<<res<<endl;
    return 0;
}
0