結果
| 問題 |
No.2744 Power! or +1
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-17 12:17:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,116 ms / 3,000 ms |
| コード長 | 1,401 bytes |
| コンパイル時間 | 917 ms |
| コンパイル使用メモリ | 84,484 KB |
| 最終ジャッジ日時 | 2025-02-21 02:49:00 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
using ll = long long;
int main(){
ll n, a, b, c;
cin >> n >> a >> b >> c;
vector<vector<pair<int,ll>>> graph(n * 2 + 1);
// グラフの構築
// 操作1
for(int i = 1; i < n * 2; i++){
graph[i].emplace_back(i + 1, a);
}
// 操作2
for(int i = 1; i < n * 2; i++){
ll nwb = b, next = i % n, up = (n <= i);
while(nwb <= n * a){
graph[i].emplace_back(n * up + next, nwb);
nwb *= b;
next *= i;
if(next >= n) up = 1;
next %= n;
}
}
// 操作3
ll next = 1, up = 0;
for(int i = 1; i < n * 2; i++){
next *= i;
if(next >= n) up = 1;
next %= n;
graph[i].emplace_back(up * n + next, c);
}
vector<ll> cost(n * 2 + 1, 1e18);
cost[1] = 0;
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> que;
que.push({0, 1});
while(que.size()){
auto[c, p] = que.top();
que.pop();
if(c != cost[p]) continue;
for(auto edge : graph[p]){
if(cost[edge.first] > cost[p] + edge.second){
cost[edge.first] = cost[p] + edge.second;
que.push({cost[edge.first], edge.first});
}
}
}
cout << min(cost[n], cost[n * 2]) << endl;
}