結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-28 14:26:52 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 401 ms / 5,000 ms |
| + 592µs | |
| コード長 | 663 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
#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;
}