結果

問題 No.2146 2 Pows
ユーザー sotanishysotanishy
提出日時 2022-12-03 00:29:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,298 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 203,824 KB
実行使用メモリ 184,944 KB
最終ジャッジ日時 2024-04-18 09:35:55
合計ジャッジ時間 6,946 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }
template <typename T> bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N, A, B, C;
    cin >> N >> A >> B >> C;
    int L = 31;
    vector<ll> ans(N, 1e18), dist(N*L, 1e18);
    using P = pair<ll, int>;
    priority_queue<P, vector<P>, greater<>> pq;
    rep(z,0,L) pq.push({A+B+z*C, N*z+(1LL<<z)%N});

    while (!pq.empty()) {
        auto [d, v] = pq.top();
        pq.pop();
        if (d > dist[v]) continue;
        int z = v/N, i = v%N;
        chmin(ans[i], d);

        ll nd = d+A, u = N*z+(i+(1LL<<z))%N;
        if (dist[u] > nd) {
            dist[u] = nd;
            pq.push({nd, u});
        }

        rep(w,z+1,L) {
            ll nd = d+B+(w-z)*C, u = N*w+i;
            if (dist[u] > nd) {
                dist[u] = nd;
                pq.push({nd, u});
            }
        }
    }
    rep(i,0,N) cout << ans[i] << "\n";
}
0