結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-08 19:23:21 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 823 bytes |
| コンパイル時間 | 6,380 ms |
| コンパイル使用メモリ | 218,376 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-06-08 19:23:29 |
| 合計ジャッジ時間 | 6,836 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin>>N;
ll num; cin>>num;
vector<int> A(N);
for(int&x:A)cin>>x;
vector<set<int>> dp(N+1);
for(int i=0;i<=N;++i) dp[i]=set<int>();
dp[N].insert(num);
for(int i=N;i>0;--i){
int x=A[i-1];
for(auto&y: dp[i]){
if(y-x>=0) dp[i-1].insert(y-x);
if(y%x==0) dp[i-1].insert(y/x);
}
}
assert(dp[0].count(0));
string ans = "";
int x=0;
for(int n=1;n<=N;++n){
int y=A[n-1];
if(dp[n].count(x+y)){
x+=y;
ans.push_back('+');
} else{
x *= y;
ans.push_back('*');
}
}
cout<<ans.substr(1)<<endl;
return 0;
}