結果

問題 No.2146 2 Pows
ユーザー 👑 rin204
提出日時 2022-12-02 23:30:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 291 ms / 3,000 ms
コード長 827 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 200,448 KB
最終ジャッジ日時 2025-02-09 04:27:42
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1LL << 60;

void solve(){
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<ll> dist(2 * n, inf);
	using P = pair<ll, int>;
	priority_queue<P, vector<P>, greater<P>> hq;
	hq.push({a + b, 3});
	dist[3] = a + b;
	while(!hq.empty()){
		ll d = hq.top().first;
		int pos = hq.top().second;
		hq.pop();
		if(dist[pos] < d) continue;
		int k = pos >> 1;
		int t = pos & 1;

		int npos = (2 * k) % n * 2;
		if(dist[npos] > d + c){
			dist[npos] = d + c;
			hq.push({d + c, npos});
		}

		npos = (pos + 2) | 1;
		npos %= (2 * n);
		ll nd = d + a;
		if(t == 0) nd += b;
		if(dist[npos] > nd){
			dist[npos] = nd;
			hq.push({nd, npos});
		}
	}
	for(int i = 0; i < 2 * n; i += 2){
		cout << min(dist[i], dist[i + 1]) << endl;;
	}
}

int main(){
	solve();
}
0