結果

問題 No.2744 Power! or +1
ユーザー 0214sh70214sh7
提出日時 2024-04-21 05:02:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,513 bytes
コンパイル時間 3,459 ms
コンパイル使用メモリ 210,320 KB
実行使用メモリ 348,120 KB
最終ジャッジ日時 2024-04-21 05:02:33
合計ジャッジ時間 11,698 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 214 ms
71,824 KB
testcase_02 AC 49 ms
16,508 KB
testcase_03 AC 36 ms
18,844 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 236 ms
104,184 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PP;
// #define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ORREP(i,n) for(ll i=(n);i>=1;--i)
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

class Dijkstra{
    // Copyright (c) 2023 0214sh7
    // https://github.com/0214sh7/library/
    private:
    typedef std::pair<long long,int> P;
    std::vector<std::vector<P>> G;
    int V;
    // long long INF = (1LL<<61);
    std::priority_queue<P,std::vector<P>,std::greater<P>> que;
    
    public:
    void init(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){
        //頂点数を決定する
        V=N;
        
        //辺集合を扱いやすい形式に変換する
        G.resize(V);
        for(int i=0;i<edge.size();i++){
            int from=edge[i].first.first,to=edge[i].first.second;
            long long cost=edge[i].second;
            G[from].push_back({cost,to});
        }
    }
    
    Dijkstra(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){
        init(N,edge);
    }

    std::vector<long long> solve(int s){
        std::vector<long long> d;
        //INFで初期化する
        for(int i=0;i<V;i++){
            d.push_back(INF);
        }
        d[s]=0;
        que.push({0,s});
        //queは{cost,to}をコストが小さい順に出す
        while(!que.empty()){
            P p = que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            for(int i=0;i<G[v].size();i++){
                P e = G[v][i];
                if(d[e.second]>d[v]+e.first){
                    d[e.second] = d[v]+e.first;
                    que.push({d[e.second],e.second});
                }
            }
        }
        return d;
    }
};

int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);

    ll N,A,B,C;
    cin >> N >> A >> B >> C;
    std::vector<std::pair<std::pair<int,int>,long long>> E;
    
    //操作1
    REP(i,2*N){
        E.push_back({{i,i+1},A});
    }
    
    //操作2
    REP(i,N){
        if(i<2)continue;
        ll x = i*i;
        ll b = B*B;
        rep(k,2,60){
            if(k==2 || k%2==1){
                E.push_back({{i,min(x,N+x%N)},b});
                E.push_back({{N+i,N+x%N},b}); 
            }
            x *= i;
            b *= B;
            if(b>N*A)break;
            if(x>=N && b>C)break;
        }
        
    }
    
    //操作3
    ll f = 1;
    OREP(i,2*N){
        ll e = (f>=N?N+f%N:f);
        E.push_back({{i,e},C});
        f *= i+1;
        f = min(f,N+f%N);
    }
    
    // cout << E.size() << endl;
    // REP(i,E.size()){
    //     cout << E[i].first.first MM E[i].first.second MM E[i].second << endl; 
    // }
    // REP(i,E.size()){
    //     if(E[i].second<0){
    //         cout << E[i].first.first MM E[i].first.second MM E[i].second << endl; 
    //     }
    // }
    
    Dijkstra dijkstra(2*N+1,E);
    std::vector<long long> D = dijkstra.solve(1);
    
    cout << min(D[N],D[2*N]) << endl;
    
    return 0;
    
}
0