結果

問題 No.10 +か×か
コンテスト
ユーザー Rumain831
提出日時 2026-07-28 14:26:52
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 401 ms / 5,000 ms
+ 592µs
コード長 663 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,690 ms
コンパイル使用メモリ 204,420 KB
実行使用メモリ 303,820 KB
最終ジャッジ日時 2026-07-28 14:27:10
合計ジャッジ時間 4,144 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long;
void chmax(string& a, string b){a=max(a, b);}

int main(void){
  int n, total; cin >> n >> total;
  vector<int> a(n);
  for(auto&x:a) cin >> x;
  vector dp(n, vector<string>(total+1, ")"));
  if(a[0]<=total) dp[0][a[0]]="";
  for(int i=0; i<n-1; i++)for(int j=0; j<=total; j++){
    for(int k=0; k<2; k++)if(dp[i][j]!=")"){
      int nadd=j+a[i+1];
      if(nadd<=total) chmax(dp[i+1][nadd], dp[i][j]+'+');
      int nmul=j*a[i+1];
      if(nmul<=total) chmax(dp[i+1][nmul], dp[i][j]+'*');
    }
  }
  cout << dp[n-1][total] << endl;
  return 0; 
}
0