結果
問題 | No.2146 2 Pows |
ユーザー |
![]() |
提出日時 | 2022-12-03 19:14:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 122 ms / 3,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 2,018 ms |
コンパイル使用メモリ | 200,172 KB |
最終ジャッジ日時 | 2025-02-09 04:48:14 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 |
ソースコード
#include<bits/stdc++.h>using namespace std;#define INF 1234567890#define ll long longint N, A, B, C;ll dist[200001][2];int main(){ios::sync_with_stdio(0); cin.tie(0);cin.exceptions(ios::badbit | ios::failbit);cin >> N >> A >> B >> C;memset(dist, 0x3f, sizeof(dist));priority_queue<tuple<ll, int, int>, vector<tuple<ll, int, int> >, greater<tuple<ll, int, int> > > pq;pq.push({0, N, 0}), dist[N][0] = 0; // must be nonempty!!while(!pq.empty()){auto [d,i,j] = pq.top(); pq.pop();if (dist[i][j] < d) continue;// case 1. add 1ll nd = d + A + (j==0?B:0);int ni = (i+1)%N;int nj = 1;if (dist[ni][nj] > nd) pq.push({nd, ni, nj}), dist[ni][nj] = nd;// case 2. mul 2if (d == 0) continue;nd = d + C;ni = (i*2)%N;nj = 0;if (dist[ni][nj] > nd) pq.push({nd, ni, nj}), dist[ni][nj] = nd;}for(int i=0; i<N; i++)cout << min(dist[i][0], dist[i][1]) << "\n";return 0;}