結果

問題 No.332 数列をプレゼントに
ユーザー btkbtk
提出日時 2015-12-25 02:05:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,393 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 162,704 KB
実行使用メモリ 11,368 KB
最終ジャッジ日時 2023-10-19 03:28:06
合計ジャッジ時間 6,509 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,916 KB
testcase_01 AC 3 ms
8,916 KB
testcase_02 AC 3 ms
8,916 KB
testcase_03 AC 3 ms
8,916 KB
testcase_04 AC 4 ms
8,916 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 AC 4 ms
8,964 KB
testcase_08 WA -
testcase_09 AC 3 ms
8,936 KB
testcase_10 AC 4 ms
8,920 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 4 ms
8,916 KB
testcase_18 WA -
testcase_19 AC 3 ms
8,916 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 5 ms
8,980 KB
testcase_25 AC 3 ms
8,980 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 4 ms
8,980 KB
testcase_29 AC 5 ms
8,980 KB
testcase_30 WA -
testcase_31 AC 4 ms
8,980 KB
testcase_32 AC 5 ms
8,980 KB
testcase_33 AC 4 ms
8,916 KB
testcase_34 AC 5 ms
8,916 KB
testcase_35 AC 11 ms
8,916 KB
testcase_36 AC 3 ms
8,916 KB
testcase_37 WA -
testcase_38 AC 3 ms
8,916 KB
testcase_39 WA -
testcase_40 AC 3 ms
8,920 KB
testcase_41 AC 4 ms
8,920 KB
testcase_42 AC 3 ms
8,916 KB
testcase_43 AC 4 ms
8,928 KB
testcase_44 WA -
testcase_45 AC 123 ms
8,916 KB
testcase_46 AC 3 ms
8,924 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     LL X;scanf("%d %lld",&n,&X);
      |          ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:46:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |         int w;scanf("%d",&w);
      |               ~~~~~^~~~~~~~~

ソースコード

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){
        int k=(int)(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=min(top+w,1000000);
            for(int j = top; j >= w; j--)
                if(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