結果

問題 No.1862 Copy and Paste
ユーザー rogi52
提出日時 2022-03-04 22:16:12
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,107 bytes
コンパイル時間 14,420 ms
コンパイル使用メモリ 286,344 KB
最終ジャッジ日時 2025-01-28 05:27:36
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll C = numeric_limits<int>::max();

inline ll f(int s, int t){ return s * C + t; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    using ll = long long;
    ll A,B,N; cin >> A >> B >> N;
    using P = pair<ll,ll>;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push({0LL, f(1, 0)});
    unordered_map<ll,ll> mp;
    mp[f(1, 0)] = 0;
    while(!q.empty()) {
        auto [dist, p] = q.top(); q.pop();
        int s = (int)(p / C), t = p % C;
        if(dist != mp[f(s, t)]) continue;

        if(s >= N) {
            cout << dist << endl; return 0;
        }

        if(!mp.count(f(s, s)) || mp[f(s, s)] > dist + A) {
            mp[f(s, s)] = dist + A;
            q.push({dist + A, f(s, s)});
        }

        if(!mp.count(f(s + t, t)) || mp[f(s + t, t)] > dist + B) {
            mp[f(s + t, t)] = dist + B;
            q.push({dist + B, f(s + t, t)});
        }
    }
}
0