結果

問題 No.1532 Different Products
ユーザー noya2noya2
提出日時 2021-06-04 22:08:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,071 bytes
コンパイル時間 4,112 ms
コンパイル使用メモリ 274,164 KB
実行使用メモリ 203,592 KB
最終ジャッジ日時 2024-11-19 14:56:11
合計ジャッジ時間 133,371 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 456 ms
35,896 KB
testcase_02 AC 32 ms
6,820 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 2 ms
6,820 KB
testcase_05 AC 2 ms
6,820 KB
testcase_06 AC 3 ms
6,816 KB
testcase_07 AC 32 ms
6,820 KB
testcase_08 AC 112 ms
12,688 KB
testcase_09 AC 117 ms
13,756 KB
testcase_10 AC 472 ms
36,352 KB
testcase_11 AC 311 ms
26,968 KB
testcase_12 AC 1,673 ms
101,132 KB
testcase_13 AC 463 ms
34,520 KB
testcase_14 AC 3,483 ms
166,004 KB
testcase_15 AC 30 ms
6,816 KB
testcase_16 AC 620 ms
43,936 KB
testcase_17 AC 300 ms
24,248 KB
testcase_18 AC 169 ms
15,548 KB
testcase_19 AC 1,642 ms
95,556 KB
testcase_20 AC 3,274 ms
169,648 KB
testcase_21 AC 880 ms
60,376 KB
testcase_22 AC 712 ms
49,460 KB
testcase_23 AC 196 ms
17,664 KB
testcase_24 AC 2,947 ms
156,420 KB
testcase_25 AC 1,420 ms
87,000 KB
testcase_26 AC 146 ms
13,500 KB
testcase_27 AC 1,340 ms
80,884 KB
testcase_28 AC 857 ms
59,760 KB
testcase_29 AC 974 ms
67,588 KB
testcase_30 AC 1,881 ms
106,712 KB
testcase_31 AC 1,916 ms
107,340 KB
testcase_32 AC 2,266 ms
121,688 KB
testcase_33 AC 1,639 ms
96,440 KB
testcase_34 AC 2,782 ms
144,528 KB
testcase_35 AC 2,164 ms
119,960 KB
testcase_36 AC 2,759 ms
143,572 KB
testcase_37 AC 659 ms
51,504 KB
testcase_38 AC 2,819 ms
151,120 KB
testcase_39 AC 2,410 ms
134,672 KB
testcase_40 AC 2,472 ms
138,888 KB
testcase_41 AC 3,858 ms
196,660 KB
testcase_42 AC 3,289 ms
174,864 KB
testcase_43 AC 3,621 ms
181,720 KB
testcase_44 TLE -
testcase_45 AC 3,962 ms
200,148 KB
testcase_46 AC 3,787 ms
193,748 KB
testcase_47 AC 3,968 ms
202,940 KB
testcase_48 AC 3,937 ms
199,696 KB
testcase_49 TLE -
testcase_50 AC 3,848 ms
198,804 KB
testcase_51 TLE -
testcase_52 AC 3,883 ms
198,116 KB
testcase_53 TLE -
testcase_54 AC 3,821 ms
197,460 KB
testcase_55 TLE -
testcase_56 AC 3,750 ms
193,748 KB
testcase_57 AC 3,775 ms
195,192 KB
testcase_58 AC 3,937 ms
199,424 KB
testcase_59 AC 3,658 ms
187,948 KB
testcase_60 TLE -
testcase_61 AC 2 ms
6,816 KB
testcase_62 AC 2 ms
6,816 KB
testcase_63 AC 3,956 ms
200,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
/*
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using bint = mp::cpp_int;
*/
#include <atcoder/all>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repp(i,n,m) for (int i = m; i < int(n); ++i)
using namespace std;
using namespace atcoder;
using namespace internal;
//alias g++='g++ -I/mnt/c/Users/Owner/Desktop/ac-library'
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 2e18;

template <typename SA>
void priv(vector<SA> &ar){
    if (ar.size() == 0) cout << endl;
    else {
        rep(i,ar.size()-1) cout << ar[i] << " ";
        cout << ar[ar.size()-1] << endl;
    } 
}
template <typename SB>
void privv(vector<vector<SB>> &ar){
    rep(i,ar.size()){
        rep(j,ar[i].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[i].size()-1] << endl;
    }
}
template <typename SC>
bool range(SC a, SC b, SC x){return (a <= x && x < b);}
bool rrange(P a, P b, P xy){
    bool s = range(a.first,b.first,xy.first);
    bool t = range(a.second,b.second,xy.second);
    return (s && t);
}
template <typename SD>
void sor(vector<SD> &ar){sort(ar.begin(),ar.end());}
template <typename SE>
void rev(vector<SE> &ar){reverse(ar.begin(),ar.end());}
template <typename SF>
bool chmin(SF &a, const SF &b){if(a>b){a = b; return true;} return false;}
template <typename SG>
bool chmax(SG &a, const SG &b){if(a<b){a = b; return true;} return false;}
template <typename SH>
void eru(vector<SH> &ar){sor(ar);ar.erase(unique(ar.begin(),ar.end()),ar.end());}
template <typename SI>
SI   last(vector<SI> &ar){return ar[ar.size()-1];}
template <typename SJ>
SJ   cel(SJ a, SJ b){if (a % b == 0) return a/b; return a/b +1;}
template <typename SK, typename SL>
void pout(pair<SK,SL> p) {cout << p.first << " " << p.second << endl;}

void yes(){cout << "Yes" << endl;}
void no (){cout << "No" << endl;}
void yn (bool t){if(t)yes();else no();}
void Yes(){cout << "YES" << endl;}
void No (){cout << "NO" << endl;}
void YN (bool t){if(t)Yes();else No();}
void dout() {cout << setprecision(20);}

vector<int> dx = {0,1,0,-1};
vector<int> dy = {1,0,-1,0};
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int r = 20;

ll cnt(vector<ll> &ar, ll x){
    ll le = -1;
    ll ri = ar.size();
    ll mid = (le + ri) / 2;
    while (ri - le > 1){
        if (ar[mid] <= x) le = mid;
        else ri = mid;
        mid = (le + ri) / 2;
    }
    return le + 1;
}

ll slv(vector<ll> &ar, ll n, ll k, map<PL,ll> &mp){
    if (mp.find(PL(n,k)) != mp.end()) return mp[PL(n,k)];
    if (n == r) return mp[PL(n,k)] = cnt(ar,k);
    if (k == 1) return mp[PL(n,k)] = 2;
    if (n > k) return mp[PL(n,k)] = slv(ar,max(ll(r),k),k,mp);
    return mp[PL(n,k)] = slv(ar,n-1,k,mp) + slv(ar,n-1,k/n,mp);
}

int main(){
    int n; cin >> n;
    ll k; cin >> k;
    ll maxk = 10000000000LL;
    if (n <= r){
        vector<ll> ar;
        rep(i,1<<n){
            ll h = 1;
            rep(j,n) if (i >> j & 1) h *= j+1;
            if (h <= maxk) ar.emplace_back(h);
        }
        sor(ar);
        cout << cnt(ar,k) - 1 << endl;
    }
    else {
        vector<ll> ar;
        rep(i,1<<r){
            ll h = 1;
            rep(j,r) if (i >> j & 1) h *= j+1;
            if (h <= maxk) ar.emplace_back(h);
        }
        sor(ar);
        map<PL,ll> mp;
        cout << slv(ar,n,k,mp) - 1 << endl;
    }
}
0