結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-08-19 01:07:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 5,000 ms |
| コード長 | 1,444 bytes |
| コンパイル時間 | 896 ms |
| コンパイル使用メモリ | 85,148 KB |
| 実行使用メモリ | 43,264 KB |
| 最終ジャッジ日時 | 2024-12-14 15:30:55 |
| 合計ジャッジ時間 | 2,035 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int N;
LL total;
int A[50];
int dpmax = 100001;
LL dp[100001][51];
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(16);//
cin>>N>>total;
rep(i,N){//[0-N) 0ori N個
cin>>A[i];
}
const LL INF = (LL)1<<55;
rep(i,100001){
rep(j,51){
dp[i][j] = INF;
}
}
LL temp;
LL mask = (LL)1<<(N-2);
dp[ A[0] ][0] = 0;
for(int i=1;i<N;++i){
for(int j=dpmax-1;j>=1;--j){
if( dp[j][i-1] < INF && 0 <= dp[j][i-1] ){
temp = j + A[i];
if( temp <= total){
dp[ temp ][i] = min( dp[ temp ][i] , dp[j][i-1] );
}
temp = j * A[i];
if( temp <= total ){
dp[ temp ][i] = min( dp[ temp ][i] , dp[j][i-1] + mask );
}
}
}
mask = mask >> 1;
}
LL ans = dp[total][N-1];
mask = (LL)1<<(N-2);
rep(i,N-1){
if( ans & mask ){
cout << "*";
}else{
cout << "+";
}
mask = mask>>1;
}cout << endl;
return 0;
}
IL_msta