結果

問題 No.1929 Exponential Sequence
ユーザー hiragn
提出日時 2023-05-22 13:10:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,235 ms
コンパイル使用メモリ 124,948 KB
最終ジャッジ日時 2025-02-13 04:07:52
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
using ll = long long;
map<ll, ll> solve(vector<ll> a, const ll &s) {
int n = a.size();
// dp[i][j]: 0,a0~a_ij
vector<map<ll, ll>> dp(n + 1);
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
auto x = a[i];
while (a[i] <= s) {
for (const auto &[k, v]: dp[i]) {
if (k + a[i] <= s) dp[i + 1][k + a[i]] += v;
}
a[i] *= x;
}
}
return dp[n]; // map(, )
}
int main() {
int n;
ll s;
cin >> n >> s;
vector<ll> a, b;
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
if (i < n / 2) {
a.emplace_back(t);
} else {
b.emplace_back(t);
}
}
auto c = solve(a, s);
auto d = solve(b, s);
// d2
for (auto i = d.begin(); i != d.end() and next(i) != d.end(); ++i) {
next(i)->second += i->second;
}
ll ans = 0;
for (const auto &[k, v]: c) {
auto it = d.upper_bound(s - k);
if (it == d.begin()) continue;
else ans += prev(it)->second * v;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0