結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
34,432 KB
testcase_01 AC 48 ms
34,432 KB
testcase_02 AC 48 ms
34,432 KB
testcase_03 AC 47 ms
34,432 KB
testcase_04 AC 46 ms
34,560 KB
testcase_05 AC 53 ms
34,432 KB
testcase_06 AC 37 ms
34,452 KB
testcase_07 AC 47 ms
34,432 KB
testcase_08 AC 48 ms
34,432 KB
testcase_09 AC 47 ms
34,560 KB
testcase_10 AC 47 ms
34,432 KB
testcase_11 AC 46 ms
34,432 KB
testcase_12 AC 47 ms
34,560 KB
testcase_13 AC 45 ms
34,432 KB
testcase_14 AC 45 ms
34,432 KB
testcase_15 AC 46 ms
34,432 KB
testcase_16 AC 45 ms
34,432 KB
testcase_17 AC 48 ms
34,432 KB
testcase_18 AC 48 ms
34,560 KB
testcase_19 AC 48 ms
34,432 KB
testcase_20 AC 48 ms
34,560 KB
testcase_21 AC 48 ms
34,560 KB
testcase_22 AC 48 ms
34,432 KB
testcase_23 AC 49 ms
34,432 KB
testcase_24 AC 48 ms
34,432 KB
testcase_25 AC 48 ms
34,432 KB
testcase_26 AC 49 ms
34,432 KB
testcase_27 AC 48 ms
34,432 KB
testcase_28 AC 47 ms
34,432 KB
testcase_29 AC 48 ms
34,432 KB
testcase_30 AC 48 ms
34,432 KB
testcase_31 AC 48 ms
34,432 KB
testcase_32 AC 48 ms
34,560 KB
testcase_33 AC 46 ms
34,432 KB
testcase_34 AC 48 ms
34,560 KB
testcase_35 AC 48 ms
34,432 KB
testcase_36 AC 48 ms
34,432 KB
testcase_37 AC 48 ms
34,432 KB
testcase_38 AC 47 ms
34,560 KB
testcase_39 AC 49 ms
34,560 KB
testcase_40 AC 48 ms
34,560 KB
testcase_41 AC 49 ms
34,432 KB
testcase_42 AC 48 ms
34,432 KB
testcase_43 AC 47 ms
34,432 KB
testcase_44 AC 45 ms
34,432 KB
testcase_45 AC 46 ms
34,560 KB
testcase_46 AC 46 ms
34,560 KB
testcase_47 AC 46 ms
34,432 KB
testcase_48 AC 46 ms
34,432 KB
testcase_49 AC 46 ms
34,432 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 = 4e6;
    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