結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2017-07-17 23:33:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,085 bytes |
コンパイル時間 | 1,638 ms |
コンパイル使用メモリ | 90,348 KB |
実行使用メモリ | 814,948 KB |
最終ジャッジ日時 | 2024-10-08 07:24:01 |
合計ジャッジ時間 | 6,801 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 MLE * 1 -- * 8 |
ソースコード
#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; }