結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
monnu
|
| 提出日時 | 2021-07-12 00:41:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 5,000 ms |
| コード長 | 904 bytes |
| コンパイル時間 | 1,864 ms |
| コンパイル使用メモリ | 173,892 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-14 15:47:54 |
| 合計ジャッジ時間 | 2,373 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
//#define MOD 1000000007
#define MOD 998244353
//#define INF 1000000000
#define INF 1000000000000000000
int main(){
int N;
int S;
cin>>N>>S;
vector<int> A(N);
for(int i=0;i<N;i++){
cin>>A[i];
}
vector<vector<bool>> dp(N,vector<bool>(S+1,false));
dp[N-1][S]=true;
for(int i=N-2;i>=0;i--){
for(int j=0;j<=S;j++){
if(j+A[i+1]<=S){
dp[i][j]=dp[i][j]|dp[i+1][j+A[i+1]];
}
if(j*A[i+1]<=S){
dp[i][j]=dp[i][j]|dp[i+1][j*A[i+1]];
}
}
}
assert(dp[0][A[0]]);
int j=A[0];
//cout<<"hello"<<endl;
for(int i=0;i<N-1;i++){
if(j+A[i+1]<=S&&dp[i+1][j+A[i+1]]){
j+=A[i+1];
cout<<'+';
}else{
j*=A[i+1];
cout<<'*';
}
}
cout<<endl;
}
monnu