結果

問題 No.2744 Power! or +1
ユーザー cho435cho435
提出日時 2024-04-20 04:05:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,257 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 204,524 KB
実行使用メモリ 39,380 KB
最終ジャッジ日時 2024-04-20 04:06:02
合計ジャッジ時間 4,190 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 397 ms
39,380 KB
testcase_01 AC 5 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 39 ms
8,792 KB
testcase_05 AC 381 ms
39,352 KB
testcase_06 WA -
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 9 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool ck(ll x,ll k,ll m){
	double dx=x;
	rep(i,k) dx*=x;
	return dx>m;
}

int main(){
	ll n,a,b,c;
	cin>>n>>a>>b>>c;
	vector<ll> fac(n,1);
	ll ud=-1;
	for(ll i=2;i<n;i++){
		if(ud==-1){
			fac.at(i)=fac.at(i-1)*i;
			if(fac.at(i)>=n){
				ud=i;
				fac.at(i)%=n;
			}
		}else{
			fac.at(i)=fac.at(i-1)*i%n;
		}		
	}
	ll mxc=n*a;
	vector<ll> cs(n+1,1e18);
	priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
	pq.push({0,1});
	while(!pq.empty()){
		auto[sc,v]=pq.top();
		pq.pop();
		if(cs.at(v)!=1e18) continue;
		cs.at(v)=sc;
		if(v==n) break;
		if(v==0){
			pq.push({sc+c,n});
			continue;
		}
		if(cs.at(v+1)==1e18){
			pq.push({sc+a,v+1});
		}
		{
			ll nx=1;
			ll pw=1;
			int flg=0;
			for(int k=1;1;k++){
				nx=(nx*v);
				if(nx>n){
					nx%=n;
					flg=1;
				}
				if(ck(b,k,mxc)) break;
				pw*=b;
				if(cs.at(nx)==1e18){
					pq.push({sc+pw,nx});
				}
				if(flg&&cs.at(0)==1e18){
					pq.push({sc+pw,0});
				}
			}
		}
		{
			int nx=fac.at(v);
			if(nx==0) nx=n;
			if(cs.at(nx)==1e18){
				pq.push({sc+c,nx});
			}
			if(ud<=v&&cs.at(0)==1e18){
				pq.push({sc+c,0});
			}
		}
	}
	cout<<cs.at(n)<<endl;
}
0