結果

問題 No.10 +か×か
ユーザー giregire
提出日時 2018-10-01 10:36:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 855 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 73,332 KB
実行使用メモリ 30,976 KB
最終ジャッジ日時 2024-04-20 13:59:04
合計ジャッジ時間 3,869 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,508 KB
testcase_01 AC 5 ms
9,528 KB
testcase_02 AC 5 ms
9,420 KB
testcase_03 WA -
testcase_04 AC 30 ms
10,756 KB
testcase_05 AC 6 ms
9,548 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 6 ms
9,480 KB
testcase_11 AC 4 ms
9,532 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];
		}
	}
	cout << bf[total] << endl;
	return 0;
}
0