結果

問題 No.2798 Multiple Chain
ユーザー GOTKAKOGOTKAKO
提出日時 2024-06-28 23:51:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,991 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 211,892 KB
実行使用メモリ 82,700 KB
最終ジャッジ日時 2024-06-28 23:51:51
合計ジャッジ時間 10,062 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 14 ms
5,788 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 24 ms
5,376 KB
testcase_06 AC 32 ms
7,952 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 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 393 ms
49,036 KB
testcase_16 AC 490 ms
55,440 KB
testcase_17 AC 552 ms
59,532 KB
testcase_18 AC 624 ms
82,700 KB
testcase_19 AC 737 ms
82,596 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 5 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 WA -
testcase_33 AC 3 ms
5,376 KB
testcase_34 WA -
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 5 ms
5,376 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 4 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 202 ms
22,392 KB
testcase_41 AC 826 ms
45,456 KB
testcase_42 AC 1,621 ms
82,624 KB
testcase_43 AC 907 ms
47,120 KB
testcase_44 AC 315 ms
24,440 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 4 ms
5,376 KB
testcase_52 AC 4 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long N; cin >> N;
    long long memoN = N;
    vector<int> pf;
    {
        int e2 = 0,e3 = 0;
        while(N%2 == 0) e2++,N /= 2;
        while(N%3 == 0) e3++,N /= 3;
        if(e2) pf.push_back(e2);
        if(e3) pf.push_back(e3);
    }
    {
        long long i=5;
        while(i*i*i <= memoN){
            int e = 0;
            while(N%i == 0) e++,N /= i;
            if(e) pf.push_back(e);
            e = 0; i += 2;
            while(N%i == 0) e++,N /= i;
            if(e) pf.push_back(e);
            i += 4;
        }
        if(N != 1) pf.push_back(1);
    }


    int answer = 0,n = pf.size();
    vector<int> multi(n+1,1);
    for(int i=1; i<=n; i++){
        int now = pf.at(i-1)+1;
        multi.at(i) = multi.at(i-1)*now;
    }
    swap(pf,multi); //まちがえた.

    unordered_map<long long,long long> M;
    auto dfs = [&](auto dfs,int left,int need) -> long long {
        long long &ret = M[1001001001LL*left+need];
        if(ret){answer += ret; return ret;}

        for(int i=0; i<n; i++){
            int le = left%pf.at(i+1)/pf.at(i),ne = need%pf.at(i+1)/pf.at(i);
            if(ne > le) return 0;
            left -= ne*pf.at(i);
        }
        answer++; ret++;

        int next = left;
        if(need) ret += dfs(dfs,left,need);

        while(true){
            int pos = 0;
            while(pos != n){
                int now = next%pf.at(pos+1)/pf.at(pos);
                if(now == 0){
                    next += left%pf.at(pos+1)/pf.at(pos)*pf.at(pos);
                    need -= left%pf.at(pos+1)/pf.at(pos)*pf.at(pos);
                    pos++;
                }
                else{next -= pf.at(pos),need += pf.at(pos); break;}
            }
            if(pos == n) break;
            ret += dfs(dfs,next,need);
        }
        return ret;
    };
    dfs(dfs,pf.at(n)-1,0);
    cout << answer << endl;
}
0