結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
65,792 KB
testcase_01 AC 91 ms
65,664 KB
testcase_02 AC 104 ms
65,664 KB
testcase_03 AC 90 ms
65,664 KB
testcase_04 AC 91 ms
65,792 KB
testcase_05 AC 93 ms
65,664 KB
testcase_06 AC 85 ms
65,664 KB
testcase_07 AC 91 ms
65,792 KB
testcase_08 AC 89 ms
65,664 KB
testcase_09 AC 92 ms
65,664 KB
testcase_10 AC 88 ms
65,664 KB
testcase_11 AC 88 ms
65,664 KB
testcase_12 AC 89 ms
65,792 KB
testcase_13 AC 86 ms
65,664 KB
testcase_14 AC 85 ms
65,664 KB
testcase_15 AC 86 ms
65,792 KB
testcase_16 AC 88 ms
65,664 KB
testcase_17 AC 93 ms
65,664 KB
testcase_18 AC 87 ms
65,664 KB
testcase_19 AC 90 ms
65,792 KB
testcase_20 AC 90 ms
65,664 KB
testcase_21 AC 91 ms
65,792 KB
testcase_22 AC 90 ms
65,664 KB
testcase_23 AC 91 ms
65,664 KB
testcase_24 AC 90 ms
65,792 KB
testcase_25 AC 89 ms
65,792 KB
testcase_26 AC 91 ms
65,664 KB
testcase_27 AC 93 ms
65,664 KB
testcase_28 AC 90 ms
65,792 KB
testcase_29 AC 90 ms
65,664 KB
testcase_30 AC 93 ms
65,664 KB
testcase_31 AC 93 ms
65,792 KB
testcase_32 AC 93 ms
65,664 KB
testcase_33 AC 91 ms
65,792 KB
testcase_34 AC 89 ms
65,792 KB
testcase_35 AC 92 ms
65,792 KB
testcase_36 AC 93 ms
65,792 KB
testcase_37 AC 91 ms
65,664 KB
testcase_38 AC 91 ms
65,664 KB
testcase_39 AC 92 ms
65,792 KB
testcase_40 AC 92 ms
65,792 KB
testcase_41 AC 92 ms
65,792 KB
testcase_42 AC 92 ms
65,664 KB
testcase_43 AC 89 ms
65,664 KB
testcase_44 AC 86 ms
65,664 KB
testcase_45 AC 89 ms
65,664 KB
testcase_46 AC 89 ms
65,664 KB
testcase_47 AC 85 ms
65,664 KB
testcase_48 AC 88 ms
65,664 KB
testcase_49 AC 89 ms
65,664 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 = 8e6;
    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