結果

問題 No.2146 2 Pows
ユーザー tree_splaytree_splay
提出日時 2022-12-03 19:14:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 3,000 ms
コード長 929 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 201,564 KB
実行使用メモリ 10,644 KB
最終ジャッジ日時 2024-04-19 05:44:22
合計ジャッジ時間 6,557 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,784 KB
testcase_01 AC 3 ms
6,656 KB
testcase_02 AC 3 ms
6,656 KB
testcase_03 AC 4 ms
6,784 KB
testcase_04 AC 3 ms
6,656 KB
testcase_05 AC 69 ms
7,444 KB
testcase_06 AC 90 ms
8,464 KB
testcase_07 AC 73 ms
10,512 KB
testcase_08 AC 84 ms
10,644 KB
testcase_09 AC 105 ms
10,552 KB
testcase_10 AC 5 ms
6,784 KB
testcase_11 AC 4 ms
6,656 KB
testcase_12 AC 4 ms
6,656 KB
testcase_13 AC 4 ms
6,784 KB
testcase_14 AC 3 ms
6,784 KB
testcase_15 AC 7 ms
6,804 KB
testcase_16 AC 46 ms
7,576 KB
testcase_17 AC 56 ms
7,444 KB
testcase_18 AC 22 ms
6,912 KB
testcase_19 AC 79 ms
8,468 KB
testcase_20 AC 87 ms
8,592 KB
testcase_21 AC 33 ms
8,468 KB
testcase_22 AC 84 ms
10,516 KB
testcase_23 AC 57 ms
8,596 KB
testcase_24 AC 59 ms
7,576 KB
testcase_25 AC 72 ms
7,444 KB
testcase_26 AC 95 ms
8,464 KB
testcase_27 AC 73 ms
7,572 KB
testcase_28 AC 68 ms
7,448 KB
testcase_29 AC 21 ms
6,932 KB
testcase_30 AC 50 ms
7,576 KB
testcase_31 AC 61 ms
7,448 KB
testcase_32 AC 19 ms
6,932 KB
testcase_33 AC 57 ms
7,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define INF 1234567890
#define ll long long

int 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 1
		ll 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 2
		if (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;
}
0