結果

問題 No.10 +か×か
ユーザー cureskolcureskol
提出日時 2020-03-27 10:34:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 569 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 168,624 KB
実行使用メモリ 28,208 KB
最終ジャッジ日時 2023-08-30 16:15:49
合計ジャッジ時間 4,741 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
28,208 KB
testcase_01 AC 13 ms
27,912 KB
testcase_02 AC 12 ms
28,108 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 179 ms
27,956 KB
testcase_06 RE -
testcase_07 AC 338 ms
28,068 KB
testcase_08 RE -
testcase_09 AC 115 ms
27,980 KB
testcase_10 AC 27 ms
28,040 KB
testcase_11 AC 24 ms
27,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[51][123456],n,s;
vector<int> v;
bool can(int a){
  memset(dp,0,sizeof(dp));
  v[a+1]+=v[a];
  dp[a+2][v[a+1]]++;
  for(int i=a+2;i<n;i++){
    for(int j=s;j>=0;j--){
      dp[i+1][j+v[i]]+=dp[i][j];
      dp[i+1][j*v[i]]+=dp[i][j];
    }
  }
  v[a+1]-=v[a];
  return dp[n][s];
}


signed main(){
  cin>>n>>s;
  v.resize(n);
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=0;i<n-1;i++){
    if(can(i)){
      cout<<'+';
      v[i+1]+=v[i];
    }
    else{
      cout<<'*';
      v[i+1]*=v[i];
    }
  }
  cout<<endl;
}
0