結果

問題 No.10 +か×か
ユーザー SakaTakuSakaTaku
提出日時 2020-09-12 04:23:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 935 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 172,272 KB
実行使用メモリ 348,288 KB
最終ジャッジ日時 2023-08-28 17:11:09
合計ジャッジ時間 12,320 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
159,752 KB
testcase_01 AC 61 ms
159,664 KB
testcase_02 AC 61 ms
159,684 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 76 ms
159,684 KB
testcase_06 RE -
testcase_07 AC 312 ms
235,320 KB
testcase_08 AC 96 ms
168,408 KB
testcase_09 AC 86 ms
163,888 KB
testcase_10 AC 61 ms
159,608 KB
testcase_11 AC 61 ms
159,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
string dp[50][100001];
int main() {
   int N,Total;cin>>N>>Total;
   vector<int>A(N);
   rep(i,N)cin>>A[i];
   dp[0][A[0]]="+";
   for (int i = 1; i < N; i++)
   {
      rep(j,Total+1){
         if(!dp[i-1][j].empty()){
            int plus=j+A[i];
            int multi=j*A[i];
            if(!dp[i][plus].empty()){
               if((dp[i-1][j]+'+')>dp[i][plus])
               dp[i][plus]=dp[i-1][j]+'+';
            }
            else if(plus<=Total)dp[i][plus]=dp[i-1][j]+'+';
            if(!dp[i][multi].empty()){
               if((dp[i-1][j]+'*')>dp[i][multi])
               dp[i][multi]=dp[i-1][j]+'*';
            }
            else if(multi<=Total)dp[i][multi]=dp[i-1][j]+'*';
         }
      }
   }
   dp[N-1][Total].erase(dp[N-1][Total].begin());
   cout<<dp[N-1][Total]<<endl;  
}
0