結果

問題 No.473 和と積の和
ユーザー milanis48663220milanis48663220
提出日時 2021-05-13 00:36:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 3,000 ms
コード長 2,392 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 133,188 KB
実行使用メモリ 10,824 KB
最終ジャッジ日時 2023-10-24 19:16:34
合計ジャッジ時間 4,156 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 196 ms
6,852 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 131 ms
10,824 KB
testcase_26 AC 107 ms
6,204 KB
testcase_27 AC 54 ms
6,628 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 31 ms
7,204 KB
testcase_35 AC 120 ms
7,204 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 247 ms
7,204 KB
testcase_39 AC 202 ms
5,288 KB
testcase_40 AC 118 ms
5,288 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 27 ms
10,160 KB
testcase_43 AC 51 ms
10,160 KB
testcase_44 AC 167 ms
10,160 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

vector<ll> enumarate_facs(ll n){
    vector<ll> ans;
    for(int i = 1; i*i <= n; i++){
        if(n%i == 0){
            ans.push_back(i);
            if(i*i != n) ans.push_back(n/i);
        }
    }
    sort(ans.begin(), ans.end());
    return ans;
}

ll n, x;
int ans;
void dfs(int i, int j, int k, vector<ll> &facs, vector<vector<int>> &inv){
    int m = facs.size();
    // cout << "dfs(" << i << "," << facs[j] << "," << facs[k] << ")" << endl;
    double rem = (double)x/(double)facs[k];
    bool too_large = [&]() -> bool{
        double t = 0.5*facs[k];
        for(int l = i; l < n; l++){
            t *= facs[j];
            if(t > x) return true;
        }
        return false;
    }();
    if(too_large) {
        return;
    }
    if(i == n){
        if(k == m-1) ans++;
        return;
    }
    for(int l = max(j, 1); l < m; l++){
        if(inv[k][l] == -1) continue;
        dfs(i+1, l, inv[k][l], facs, inv);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> n >> x;
    if(n > 30){
        cout << 0 << endl;
        return 0;
    }
    x++;
    auto facs = enumarate_facs(x);
    int m = facs.size();
    vector<vector<int>> inv(m, vector<int>(m, -1));
    map<ll, int> mp = [&](){
        map<ll, int> ans;
        for(int i = 0; i < m; i++) ans[facs[i]] = i;
        return ans;
    }();
    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            ll p = facs[i]*facs[j];
            if(p > x) continue;
            if(x%p == 0){
                // cout << facs[i] << '*' << facs[j] << '=' << facs[mp[p]] << endl;
                inv[i][j] = mp[p];
            }
        }
    }
    dfs(0, 0, 0, facs, inv);
    cout << ans << endl;
}
0