結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 NachiaNachia
提出日時 2023-07-21 21:39:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 86,380 KB
実行使用メモリ 32,768 KB
最終ジャッジ日時 2024-04-15 20:58:10
合計ジャッジ時間 2,481 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 31 ms
29,824 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 9 ms
9,984 KB
testcase_25 AC 9 ms
10,496 KB
testcase_26 AC 7 ms
9,600 KB
testcase_27 AC 8 ms
10,240 KB
testcase_28 AC 8 ms
9,216 KB
testcase_29 AC 20 ms
19,584 KB
testcase_30 AC 16 ms
16,768 KB
testcase_31 AC 20 ms
19,840 KB
testcase_32 AC 19 ms
19,200 KB
testcase_33 AC 18 ms
18,432 KB
testcase_34 AC 35 ms
32,768 KB
testcase_35 AC 33 ms
31,232 KB
testcase_36 AC 31 ms
30,080 KB
testcase_37 AC 34 ms
32,128 KB
testcase_38 AC 31 ms
30,848 KB
testcase_39 AC 33 ms
32,000 KB
testcase_40 AC 7 ms
7,808 KB
testcase_41 AC 6 ms
7,552 KB
testcase_42 AC 6 ms
7,936 KB
testcase_43 AC 6 ms
7,424 KB
testcase_44 AC 8 ms
10,752 KB
testcase_45 AC 6 ms
8,320 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 7 ms
8,448 KB
testcase_48 AC 9 ms
10,880 KB
testcase_49 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;


int main(){
    i64 N; cin >> N;
    vector<pair<i64, i64>> AB(3);
    rep(i,3) cin >> AB[i].first >> AB[i].second;
    sort(AB.begin(), AB.end(), [](auto a, auto b){ return a.second * b.first > b.second * a.first; });
    i64 ans = 0;
    if(N >= 4000000){
        i64 t = (N - AB[1].first * AB[2].first) / AB[0].first;
        N -= t * AB[0].first;
        ans += t * AB[0].second;
    }
    vector<i64> dp(N+1, 0);
    for(auto [a,b] : AB) for(int i=a; i<=N; i++) dp[i] = max(dp[i], dp[i-a] + b);
    ans += dp[N];
    cout << ans << endl;
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0