結果
問題 | No.2744 Power! or +1 |
ユーザー | ponjuice |
提出日時 | 2024-04-17 12:17:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 888 ms / 3,000 ms |
コード長 | 1,401 bytes |
コンパイル時間 | 825 ms |
コンパイル使用メモリ | 88,512 KB |
実行使用メモリ | 430,940 KB |
最終ジャッジ日時 | 2024-04-17 18:33:14 |
合計ジャッジ時間 | 4,364 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 888 ms
430,940 KB |
testcase_01 | AC | 82 ms
32,988 KB |
testcase_02 | AC | 15 ms
8,576 KB |
testcase_03 | AC | 22 ms
10,368 KB |
testcase_04 | AC | 63 ms
39,036 KB |
testcase_05 | AC | 668 ms
329,772 KB |
testcase_06 | AC | 291 ms
154,556 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 163 ms
49,364 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
ソースコード
#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; }