結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 tatyamtatyam
提出日時 2023-07-17 20:29:16
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 3,901 ms
コンパイル使用メモリ 282,044 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-15 20:56:47
合計ジャッジ時間 6,247 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
18,944 KB
testcase_01 AC 26 ms
18,816 KB
testcase_02 AC 26 ms
18,816 KB
testcase_03 AC 25 ms
18,816 KB
testcase_04 AC 24 ms
18,944 KB
testcase_05 AC 25 ms
18,816 KB
testcase_06 AC 24 ms
18,944 KB
testcase_07 AC 26 ms
18,816 KB
testcase_08 AC 25 ms
18,816 KB
testcase_09 AC 25 ms
18,816 KB
testcase_10 AC 24 ms
18,816 KB
testcase_11 AC 23 ms
18,816 KB
testcase_12 AC 24 ms
18,816 KB
testcase_13 AC 24 ms
18,944 KB
testcase_14 AC 24 ms
18,816 KB
testcase_15 AC 24 ms
18,816 KB
testcase_16 AC 23 ms
18,816 KB
testcase_17 AC 25 ms
18,816 KB
testcase_18 AC 25 ms
18,816 KB
testcase_19 AC 25 ms
18,816 KB
testcase_20 AC 25 ms
18,816 KB
testcase_21 AC 25 ms
18,816 KB
testcase_22 AC 25 ms
18,944 KB
testcase_23 AC 26 ms
18,816 KB
testcase_24 AC 25 ms
18,944 KB
testcase_25 AC 25 ms
18,816 KB
testcase_26 AC 25 ms
18,944 KB
testcase_27 AC 25 ms
18,944 KB
testcase_28 AC 25 ms
18,816 KB
testcase_29 AC 26 ms
18,944 KB
testcase_30 AC 25 ms
18,816 KB
testcase_31 AC 27 ms
18,816 KB
testcase_32 AC 25 ms
18,816 KB
testcase_33 AC 24 ms
18,816 KB
testcase_34 AC 25 ms
18,816 KB
testcase_35 AC 25 ms
18,944 KB
testcase_36 AC 25 ms
18,816 KB
testcase_37 AC 25 ms
18,816 KB
testcase_38 AC 25 ms
18,816 KB
testcase_39 AC 25 ms
18,816 KB
testcase_40 AC 25 ms
18,816 KB
testcase_41 AC 25 ms
18,816 KB
testcase_42 AC 25 ms
18,816 KB
testcase_43 AC 25 ms
18,816 KB
testcase_44 AC 23 ms
18,816 KB
testcase_45 AC 24 ms
18,816 KB
testcase_46 AC 24 ms
18,944 KB
testcase_47 AC 24 ms
18,816 KB
testcase_48 AC 24 ms
18,944 KB
testcase_49 AC 25 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
void chmax(i64& a, i64 b) {if(a < b) a = b; }


i64 solve() {
    i64 N;
    cin >> N;
    vector<pair<i64, i64>> A(3);
    for(auto& [a, b] : A) cin >> a >> b;
    sort(A.begin(), A.end(), [&](pair<i64, i64> a, pair<i64, i64> b) { return a.first * b.second < a.second * b.first; });
    
    const i64 MX = 2e6;
    vector<i64> dp(MX + 1);
    for(i64 i = 0; i < MX; i++) for(auto [a, b] : A) if(i + a <= MX) chmax(dp[i + a], dp[i] + b);
    if(N <= MX) return dp[N];
    const auto [a, b] = A[0];
    for(i64 i = MX; ; i--) if((N - i) % a == 0) return dp[i] + (N - i) / a * b;
}
int main() {
    cout << solve() << endl;
}
0