結果

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

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
using P = pair<long long,pair<int,int>>;

int main(){
	
	
	long long n,a,b,c;
	cin>>n>>a>>b>>c;
	
	vector dis(n,vector<long long>(2,Inf64));
	
	dis[1][1] = a+b;
	priority_queue<P,vector<P>,greater<P>> Q;
	Q.emplace(a+b,make_pair(1,1));
	while(Q.size()>0){
		long long D = Q.top().first;
		int x = Q.top().second.first;
		int y = Q.top().second.second;
		Q.pop();
		if(dis[x][y]!=D)continue;
		{
			int nx = (x+1)%n;
			int ny = y;
			long long nD = D + a;
			if(y==0){
				ny = 1;
				nD += b;
			}
			if(dis[nx][ny]>nD){
				dis[nx][ny] = nD;
				Q.emplace(nD,make_pair(nx,ny));
			}
		}
		
		{
			int nx = (x*2)%n;
			int ny = 0;
			long long nD = D + c;
			if(dis[nx][ny]>nD){
				dis[nx][ny] = nD;
				Q.emplace(nD,make_pair(nx,ny));
			}
		}
		
	}
	
	rep(i,n){
		cout<<min(dis[i][0],dis[i][1])<<endl;
	}
	
	return 0;
}
0