結果

問題 No.10 +か×か
ユーザー giregire
提出日時 2018-10-01 10:53:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,074 ms / 5,000 ms
コード長 870 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 72,224 KB
実行使用メモリ 30,544 KB
最終ジャッジ日時 2023-08-21 06:24:42
合計ジャッジ時間 3,800 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,256 KB
testcase_01 AC 6 ms
9,220 KB
testcase_02 AC 5 ms
9,256 KB
testcase_03 AC 1,074 ms
30,544 KB
testcase_04 AC 53 ms
10,696 KB
testcase_05 AC 5 ms
9,232 KB
testcase_06 AC 1,032 ms
30,424 KB
testcase_07 AC 247 ms
23,576 KB
testcase_08 AC 50 ms
13,260 KB
testcase_09 AC 49 ms
14,204 KB
testcase_10 AC 6 ms
9,260 KB
testcase_11 AC 6 ms
9,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<queue>
#include<stack>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main(){
	int i, j;
	int in[50], total, n;
	vector <string> bf(100001);
	vector <string> af(100001);
	cin >> n;
	cin >> total;
	for(i = 0; i < n; i++) cin >> in[i];
	bf[in[0] * in[1]] = "*";
	bf[in[0] + in[1]] = "+";
	for(i = 2; i < n; i++){
		for(j = 0; j <=total; j++){
			if(bf[j].length()>0){
				if(j * in[i] <= total){
					if ((bf[j] + "*") > af[j* in[i]]) af[j* in[i]] = bf[j] + "*";
				}
				if(j + in[i] <= total){
					if ((bf[j] + "+") > af[j+ in[i]]) af[j+ in[i]] = bf[j] + "+";
				}
			}
		}
		for(j = 0; j <=total; j++){
			bf[j] = af[j];
			af[j] = "";
		}
	}
	cout << bf[total] << endl;
	return 0;
}
0