結果
問題 | No.1929 Exponential Sequence |
ユーザー | 👑 AngrySadEight |
提出日時 | 2022-05-06 22:33:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 3,218 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 179,240 KB |
実行使用メモリ | 22,944 KB |
最終ジャッジ日時 | 2024-09-14 03:53:42 |
合計ジャッジ時間 | 3,455 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | AC | 116 ms
22,944 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 123 ms
22,612 KB |
testcase_22 | AC | 78 ms
14,676 KB |
testcase_23 | AC | 120 ms
22,432 KB |
testcase_24 | AC | 54 ms
12,224 KB |
testcase_25 | AC | 119 ms
22,424 KB |
testcase_26 | AC | 126 ms
22,816 KB |
testcase_27 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define all(v) v.begin(), v.end() #define mod1 1000000007 #define mod2 998244353 typedef long long ll; ll my_pow(ll x, ll n, ll mod){ // 繰り返し二乗法.x^nをmodで割った余り. ll ret; if (n == 0){ ret = 1; } else if (n % 2 == 1){ ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod; } else{ ret = my_pow((x * x) % mod, n / 2, mod); } return ret; } int main(){ ll n, S; cin >> n >> S; vector<ll> a(n); rep(i,n) cin >> a[i]; if (n <= 4){ vector<vector<ll>> vec(n + 1, vector<ll>(0)); vec[0].push_back(0); for (ll i = 0; i < n; i++){ ll now = a[i]; while(true){ if (now > S){ break; } for (ll j = 0; j < vec[i].size(); j++){ if (now + vec[i][j] <= S){ vec[i + 1].push_back(now + vec[i][j]); } } now = now * a[i]; } } /*for (ll i = 0; i < vec[n].size(); i++){ cout << vec[n][i] << " "; } cout << endl;*/ cout << vec[n].size() << endl; } else{ vector<vector<ll>> former(5, vector<ll>(0)); vector<vector<ll>> latter(n - 3, vector<ll>(0)); former[0].push_back(0); latter[0].push_back(0); for (ll i = 0; i < 4; i++){ ll now = a[i]; while(true){ if (now > S){ break; } for (ll j = 0; j < former[i].size(); j++){ if (now + former[i][j] <= S){ former[i + 1].push_back(now + former[i][j]); } } now = now * a[i]; } } for (ll i = 4; i < n; i++){ ll now = a[i]; while(true){ if (now > S){ break; } for (ll j = 0; j < latter[i - 4].size(); j++){ if (now + latter[i - 4][j] <= S){ latter[i - 3].push_back(now + latter[i - 4][j]); } } now = now * a[i]; } } sort(all(former[4])); sort(all(latter[n - 4])); if (latter[n - 4].size() == 0){ cout << 0 << endl; } else{ ll ans = 0; for (ll i = 0; i < former[4].size(); i++){ if (latter[n - 4][0] + former[4][i] > S){ ans += 0; } else if (latter[n - 4][latter[n - 4].size() - 1] + former[4][i] <= S){ ans += (latter[n - 4].size()); } else{ auto itr = upper_bound(all(latter[n - 4]), S - former[4][i]); ll X = itr - latter[n - 4].begin(); ans += X; } } cout << ans << endl; } } }