結果

問題 No.10 +か×か
ユーザー goodbatongoodbaton
提出日時 2015-07-16 00:27:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,217 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 74,416 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2023-09-22 16:35:52
合計ジャッジ時間 1,276 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 8 ms
7,468 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

int dp[51][100000]; //1..* 2..+

int main(){
    int n,total;
    int A[SIZE];
    string ans;
    
    scanf("%d%d",&n,&total);

    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    
    dp[1][A[0]]=1;
    
    for(int i=1;i<n;i++){
        
        for(int j=0;j<=total;j++){
            if(dp[i][j]==0) continue;
            
            if(j*A[i]<=total){
                dp[i+1][j*A[i]]=max(dp[i+1][j*A[i]],1);
            }
            
            if(j+A[i]<=total){
                dp[i+1][j+A[i]]=max(dp[i+1][j+A[i]],2);
            }
        }
    }
    
    
    
    for(int i=n;i>=2;i--){
        if(dp[i][total]==1){
            ans+='*';
            total/=A[i-1];
        }else{
            ans+='+';
            total-=A[i-1];
        }
    }
    
    reverse(ans.begin(),ans.end());
    
    cout << ans << endl;
    
    return 0;
}
0