結果

問題 No.2744 Power! or +1
ユーザー shobonvipshobonvip
提出日時 2024-04-21 10:04:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 963 ms / 3,000 ms
コード長 2,001 bytes
コンパイル時間 4,458 ms
コンパイル使用メモリ 263,604 KB
実行使用メモリ 430,604 KB
最終ジャッジ日時 2024-04-21 10:04:37
合計ジャッジ時間 8,792 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 963 ms
430,604 KB
testcase_01 AC 121 ms
34,360 KB
testcase_02 AC 19 ms
8,704 KB
testcase_03 AC 31 ms
10,368 KB
testcase_04 AC 74 ms
39,548 KB
testcase_05 AC 739 ms
333,724 KB
testcase_06 AC 333 ms
154,364 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 268 ms
76,384 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	ll n, a, b, c; cin >> n >> a >> b >> c;
	vector<ll> dp(2 * n, 1e18);
	dp[1] = 0;
	vector ikeru(2 * n, vector<pair<int,ll>>(0));
	vector<ll> costb(1, 1);
	while(true){
		if (costb.back() * b >= 1e11) break;
		costb.push_back(costb.back() * b);
	}
	ll kaijo = 1;
	for (ll i=1; i<2*n; i++){
		kaijo *= i;
		if (kaijo >= n) kaijo = kaijo % n + n;
		ikeru[i].push_back(pair(kaijo, c));

		ll tar = i * i;
		if (tar >= n) tar = tar % n + n;
		rep(k,2,(int)costb.size()){
			ikeru[i].push_back(pair(tar, costb[k]));
			tar *= i;
			if (tar >= n) tar = tar % n + n;
		}

		tar = i + 1;
		if (tar >= n) tar = tar % n + n;
		ikeru[i].push_back(pair(tar, a));
	}

	priority_queue<pair<ll,int>> pq;
	pq.push(pair(0, 1));
	while(!pq.empty()){
		auto [tmp, i] = pq.top();
		pq.pop();
		tmp = -tmp;
		if (tmp > dp[i]) continue;
		for (auto [j, cost]: ikeru[i]){
			if (chmin(dp[j], cost + tmp)){
				pq.push(pair(-dp[j], j));
			}
		}
	}
	cout << dp[n] << '\n';
}

0