結果

問題 No.1929 Exponential Sequence
ユーザー hirakuuuuhirakuuuu
提出日時 2023-09-24 23:19:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 835 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 172,924 KB
実行使用メモリ 102,128 KB
最終ジャッジ日時 2023-09-24 23:19:49
合計ジャッジ時間 8,322 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 835 ms
102,128 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 781 ms
100,724 KB
testcase_22 AC 476 ms
67,000 KB
testcase_23 AC 788 ms
99,300 KB
testcase_24 AC 297 ms
47,804 KB
testcase_25 AC 764 ms
98,384 KB
testcase_26 AC 831 ms
101,964 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i >= n; i--)
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
// constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1LL<<60;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

vector<ll> msetToVec(multiset<ll> &s){
    vector<ll> res;
    for(auto ss: s){
        res.push_back(ss);
    }

    return res;
}

int main(){
    ll n, s; cin >> n >> s;
    vector<ll> a(8);
    rep(i, 0, n) cin >> a[i];

    multiset<ll> b, c;
    b.insert(0);
    c.insert(0);
    rep(i, 0, 4){
        if(a[i] == 0) continue;
        multiset<ll> b_;
        
        for(auto bb: b){
            ll tmp = a[i];
            while(tmp <= s){
                if(bb+tmp <= s) b_.insert(bb+tmp);
                tmp *= a[i];
            }
        }
        b = b_;
    }
    rep(i, 4, 8){
        if(a[i] == 0) continue;
        multiset<ll> c_;
        
        for(auto cc: c){
            ll tmp = a[i];
            while(tmp <= s){
                if(cc+tmp <= s) c_.insert(cc+tmp);
                tmp *= a[i];
            }
        }
        c = c_;
    }
    vector<ll> B = msetToVec(b), C = msetToVec(c);
    ll ans = 0;
    for(auto bb: B){
        ll tmp = C.end() - upper_bound(C.begin(), C.end(), s-bb);
        ans += C.size()-tmp;
    }
    cout << ans << endl;
    
    return 0;
}
0