結果
| 問題 |
No.2744 Power! or +1
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2024-04-21 10:04:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 986 ms / 3,000 ms |
| コード長 | 2,001 bytes |
| コンパイル時間 | 4,259 ms |
| コンパイル使用メモリ | 260,364 KB |
| 最終ジャッジ日時 | 2025-02-21 07:59:34 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
#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';
}
shobonvip