結果

問題 No.332 数列をプレゼントに
ユーザー btkbtk
提出日時 2015-12-25 02:19:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,381 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 147,132 KB
実行使用メモリ 9,696 KB
最終ジャッジ日時 2023-08-25 21:14:19
合計ジャッジ時間 3,877 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,316 KB
testcase_01 AC 4 ms
9,264 KB
testcase_02 AC 4 ms
9,288 KB
testcase_03 AC 4 ms
9,260 KB
testcase_04 AC 4 ms
9,200 KB
testcase_05 AC 5 ms
9,696 KB
testcase_06 AC 5 ms
9,392 KB
testcase_07 AC 4 ms
9,220 KB
testcase_08 AC 4 ms
9,416 KB
testcase_09 AC 4 ms
9,268 KB
testcase_10 AC 5 ms
9,172 KB
testcase_11 AC 5 ms
9,624 KB
testcase_12 AC 4 ms
9,536 KB
testcase_13 AC 4 ms
9,528 KB
testcase_14 AC 4 ms
9,292 KB
testcase_15 AC 5 ms
9,456 KB
testcase_16 AC 4 ms
9,248 KB
testcase_17 AC 4 ms
9,184 KB
testcase_18 AC 4 ms
9,452 KB
testcase_19 AC 4 ms
9,176 KB
testcase_20 AC 5 ms
9,400 KB
testcase_21 AC 4 ms
9,292 KB
testcase_22 AC 5 ms
9,400 KB
testcase_23 AC 5 ms
9,296 KB
testcase_24 AC 5 ms
9,404 KB
testcase_25 AC 4 ms
9,244 KB
testcase_26 AC 4 ms
9,240 KB
testcase_27 AC 5 ms
9,296 KB
testcase_28 AC 5 ms
9,316 KB
testcase_29 AC 5 ms
9,316 KB
testcase_30 AC 4 ms
9,416 KB
testcase_31 AC 4 ms
9,352 KB
testcase_32 AC 5 ms
9,404 KB
testcase_33 AC 4 ms
9,172 KB
testcase_34 AC 6 ms
9,296 KB
testcase_35 AC 13 ms
9,348 KB
testcase_36 AC 4 ms
9,172 KB
testcase_37 AC 4 ms
9,180 KB
testcase_38 AC 4 ms
9,476 KB
testcase_39 AC 4 ms
9,256 KB
testcase_40 AC 4 ms
9,240 KB
testcase_41 AC 4 ms
9,344 KB
testcase_42 AC 4 ms
9,196 KB
testcase_43 AC 4 ms
9,308 KB
testcase_44 AC 4 ms
9,176 KB
testcase_45 AC 148 ms
9,288 KB
testcase_46 AC 4 ms
9,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[1000001];
int unko[1000001];
int v[100];
pair<int,LL> pv[100];
inline void init(){
    fill(dp,dp+1000001,-1);
    dp[0]=0;
}
int ans[100];
int n;
bool dfs(int id,int p,int sz,LL now,LL X){
    if(now>X)return false;
    if(X-now<=1000000&&dp[X-now]>=0){
        LL k=(X-now);
        while(k){
            ans[p++]=dp[k]-1;
            k=unko[k];
        }
        sort(ans,ans+p);
        for(int i = 0,s=0; i < n; i++){
            if(s<p&&ans[s]==i){
                putchar('o');
                s++;
            }
            else putchar('x');
        }putchar('\n');
        return true;
    }
    if(id<sz){
        ans[p]=pv[id].first;
        if(dfs(id+1,p+1,sz,now+pv[id].second,X))return true;
        if(dfs(id+1,p,sz,now,X))return true;
    }
    return false;
}
int main() {
    init();
    LL X;scanf("%d %lld",&n,&X);
    int sz=0,top=0;
    for(int i = 0; i < n; i++){
        int w;scanf("%d",&w);
        if(w<=10000){
            top=top+w;
            for(int j = top; j >= w; j--)
                if(dp[j]<0&&dp[j-w]>=0){
                    dp[j]=i+1;
                    unko[j]=j-w;
                }
        }
        else{
            pv[sz].first=i;
            pv[sz].second=w;
            sz++;
        }
    }
    if(dfs(0,0,sz,0,X)==false)printf("No\n");
    return 0;
}
0