結果

問題 No.2146 2 Pows
ユーザー 👑 rin204rin204
提出日時 2022-12-02 23:30:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 364 ms / 3,000 ms
コード長 827 bytes
コンパイル時間 2,100 ms
コンパイル使用メモリ 203,044 KB
実行使用メモリ 10,756 KB
最終ジャッジ日時 2024-04-18 08:45:06
合計ジャッジ時間 10,403 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 313 ms
7,556 KB
testcase_06 AC 339 ms
8,484 KB
testcase_07 AC 309 ms
10,632 KB
testcase_08 AC 349 ms
10,756 KB
testcase_09 AC 364 ms
10,624 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 22 ms
5,376 KB
testcase_16 AC 210 ms
6,480 KB
testcase_17 AC 228 ms
6,648 KB
testcase_18 AC 105 ms
5,376 KB
testcase_19 AC 277 ms
7,960 KB
testcase_20 AC 301 ms
8,100 KB
testcase_21 AC 114 ms
6,440 KB
testcase_22 AC 312 ms
10,400 KB
testcase_23 AC 266 ms
8,048 KB
testcase_24 AC 232 ms
6,548 KB
testcase_25 AC 252 ms
6,888 KB
testcase_26 AC 320 ms
8,488 KB
testcase_27 AC 286 ms
7,120 KB
testcase_28 AC 250 ms
6,744 KB
testcase_29 AC 88 ms
5,376 KB
testcase_30 AC 210 ms
6,380 KB
testcase_31 AC 278 ms
7,160 KB
testcase_32 AC 50 ms
5,376 KB
testcase_33 AC 243 ms
6,776 KB
権限があれば一括ダウンロードができます

ソースコード

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