結果

問題 No.1581 Multiple Sequence
ユーザー rianoriano
提出日時 2021-07-24 19:42:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 924 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 177,500 KB
実行使用メモリ 72,408 KB
最終ジャッジ日時 2023-09-27 07:54:38
合計ジャッジ時間 5,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;

const ll mod = 1000000007;

map<Pr,ll> memo;
ll search(ll m,ll sum,vector<vector<ll>> &div){
    if(sum<0) return 0;
    if(sum==0) return 1;
    Pr p = make_pair(m,sum);
    if(memo.count(p)) return memo[p];
    ll cnt = 0;
    for(ll x:div[m]){
        cnt += search(x,sum-x,div);
    }
    memo[p] = cnt;
    //cout << m << " " << sum << " " << cnt << endl;
    return cnt;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll M; cin >> M;
    vector<vector<ll>> div(M+1);
    for(ll i=1;i<=M;i++){
        for(ll j=i;j<=M;j+=i){
            div[j].push_back(i);
        }
    }
    ll ans = 0;
    for(ll i=1;i<=M;i++){
        ans += search(i,M-i,div);
    }
    cout << ans << endl;
}
0