結果

問題 No.1862 Copy and Paste
ユーザー rogi52rogi52
提出日時 2022-03-04 22:04:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 887 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 215,732 KB
実行使用メモリ 242,284 KB
最終ジャッジ日時 2023-09-26 01:05:17
合計ジャッジ時間 10,285 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
242,284 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 25 ms
5,460 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 274 ms
17,236 KB
testcase_10 AC 42 ms
6,120 KB
testcase_11 AC 18 ms
4,812 KB
testcase_12 AC 122 ms
10,740 KB
testcase_13 AC 110 ms
9,692 KB
testcase_14 AC 10 ms
4,384 KB
testcase_15 AC 194 ms
14,096 KB
testcase_16 AC 1,053 ms
45,888 KB
testcase_17 AC 108 ms
10,100 KB
testcase_18 AC 47 ms
6,704 KB
testcase_19 AC 18 ms
4,824 KB
testcase_20 AC 112 ms
9,832 KB
testcase_21 AC 1,134 ms
49,040 KB
testcase_22 AC 144 ms
11,468 KB
testcase_23 AC 133 ms
10,764 KB
testcase_24 AC 171 ms
13,668 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 164 ms
13,532 KB
testcase_27 AC 17 ms
4,820 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

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

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

        if(s >= N) {
            ans = dist; break;
        }

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

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

    cout << ans << endl;
}
0