結果

問題 No.2390 Udon Coupon (Hard)
ユーザー GlinTFrauleinGlinTFraulein
提出日時 2023-07-20 05:45:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 4,572 ms
コンパイル使用メモリ 254,132 KB
実行使用メモリ 60,032 KB
最終ジャッジ日時 2024-04-15 20:56:54
合計ジャッジ時間 6,598 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 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 46 ms
40,832 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 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 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 16 ms
14,848 KB
testcase_25 AC 16 ms
15,744 KB
testcase_26 AC 16 ms
15,616 KB
testcase_27 AC 16 ms
15,616 KB
testcase_28 AC 15 ms
14,208 KB
testcase_29 AC 38 ms
34,176 KB
testcase_30 AC 35 ms
30,848 KB
testcase_31 AC 39 ms
33,920 KB
testcase_32 AC 38 ms
33,920 KB
testcase_33 AC 37 ms
33,152 KB
testcase_34 AC 71 ms
60,032 KB
testcase_35 AC 69 ms
56,960 KB
testcase_36 AC 65 ms
55,552 KB
testcase_37 AC 67 ms
58,624 KB
testcase_38 AC 66 ms
57,472 KB
testcase_39 AC 20 ms
19,072 KB
testcase_40 AC 16 ms
16,000 KB
testcase_41 AC 20 ms
18,560 KB
testcase_42 AC 16 ms
15,616 KB
testcase_43 AC 17 ms
16,640 KB
testcase_44 AC 4 ms
5,376 KB
testcase_45 AC 9 ms
8,832 KB
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 9 ms
8,832 KB
testcase_49 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
 
#define elif else if
#define ll long long
#define vll vector<long long>
#define vec vector
#define embk emplace_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, n, k) for (ll i = k; i < n; i++)
#define all(a) a.begin(), a.end()
#define YNeos(bool) (bool ? "Yes" : "No")
 
using namespace std;
using namespace atcoder;
const ll INF = 1LL << 60;
const ll mod = 998244353;
const double pi = acos(-1);


int main() {
  ll n; cin >> n;
  vll a(3), b(3); rep(i, 3) cin >> a[i] >> b[i];

  ll mima = min(a[0], min(a[1], a[2]));
  ll minb = min(b[0], min(b[1], b[2]));

  //うどん札1枚当たりの割引額が最も大きいものを(a[0], b[0])にする
  if (a[1] * b[0] < a[0] * b[1]) {
    swap(a[0], a[1]);
    swap(b[0], b[1]);
  }
  if (a[2] * b[0] < a[0] * b[2]) {
    swap(a[0], a[2]);
    swap(b[0], b[2]);
  }
  
  //(a[0], b[0])の割引を必ず使う回数と、DPで調べるうどん札の残り枚数を求める
  ll use_0 = max(n / a[0] - a[1] - a[2], 0LL);
  ll nokori_n = min(a[0] * (a[1] + a[2]) + (n % a[0]), n);

  //DP
  vll dp(nokori_n + 2001);
  ll dpans = 0;

  rep(i, nokori_n + 1) {
    dp[i + a[0]] = max(dp[i] + b[0], dp[i + a[0]]);
    dp[i + a[1]] = max(dp[i] + b[1], dp[i + a[1]]);
    dp[i + a[2]] = max(dp[i] + b[2], dp[i + a[2]]);
    dpans = max(dp[i], dpans);
  }

  cout << dpans + use_0 * b[0] << endl;
}
0