結果

問題 No.10 +か×か
ユーザー IL_mstaIL_msta
提出日時 2015-08-19 01:07:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 1,444 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 43,276 KB
最終ジャッジ日時 2023-08-21 06:13:41
合計ジャッジ時間 1,872 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
43,204 KB
testcase_01 AC 15 ms
43,256 KB
testcase_02 AC 15 ms
43,216 KB
testcase_03 AC 59 ms
43,196 KB
testcase_04 AC 34 ms
43,256 KB
testcase_05 AC 33 ms
43,216 KB
testcase_06 AC 58 ms
43,272 KB
testcase_07 AC 40 ms
43,276 KB
testcase_08 AC 26 ms
43,276 KB
testcase_09 AC 24 ms
43,208 KB
testcase_10 AC 17 ms
43,276 KB
testcase_11 AC 17 ms
43,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0