結果

問題 No.10 +か×か
ユーザー ldsybldsyb
提出日時 2017-07-17 23:33:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,085 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 91,344 KB
実行使用メモリ 817,516 KB
最終ジャッジ日時 2024-04-17 00:04:40
合計ジャッジ時間 5,706 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <typename T, typename U, typename V>
T find(T first, T last, U val, V func){
	for(; first != last; first++) if(func(val, *first)) return first;
	return last;
}

int main(){
	int64_t n, total;
	cin >> n >> total;
	int64_t a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	vector<pair<int64_t, string>> v;
	v.emplace_back(make_pair(a[0], ""));
	for(int i = 1; i < n; i++){
		vector<pair<int64_t, string>> next;
		for(auto p:v){
			if(p.first + a[i] <= total) next.emplace_back(make_pair(p.first + a[i], p.second + '+'));
			if(p.first * a[i] <= total) next.emplace_back(make_pair(p.first * a[i], p.second + '*'));
		}
		v = next;
	}
	sort(v.begin(), v.end(), [](pair<int64_t, string> p, pair<int64_t, string> q){return p.first == q.first ? p.second > q.second : p.first < q.first;});
	for(auto p:v) cerr << p.first << ' ' << p.second << endl;
	cout << find(v.begin(), v.end(), make_pair(total, ""), [](pair<int64_t, string> p, pair<int64_t, string> q){return p.first == q.first;})->second << endl;
}
0