結果

問題 No.2390 Udon Coupon (Hard)
ユーザー そすうぽよそすうぽよ
提出日時 2023-07-21 22:50:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 2,000 ms
コード長 2,027 bytes
コンパイル時間 2,522 ms
コンパイル使用メモリ 199,760 KB
実行使用メモリ 59,520 KB
最終ジャッジ日時 2024-04-15 21:02:52
合計ジャッジ時間 7,459 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 129 ms
37,760 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 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 45 ms
14,976 KB
testcase_25 AC 47 ms
15,104 KB
testcase_26 AC 45 ms
15,232 KB
testcase_27 AC 47 ms
15,360 KB
testcase_28 AC 39 ms
13,568 KB
testcase_29 AC 156 ms
33,792 KB
testcase_30 AC 122 ms
30,464 KB
testcase_31 AC 155 ms
33,536 KB
testcase_32 AC 159 ms
33,152 KB
testcase_33 AC 149 ms
32,512 KB
testcase_34 AC 507 ms
59,520 KB
testcase_35 AC 324 ms
56,448 KB
testcase_36 AC 474 ms
55,040 KB
testcase_37 AC 348 ms
58,112 KB
testcase_38 AC 485 ms
57,216 KB
testcase_39 AC 14 ms
13,568 KB
testcase_40 AC 46 ms
16,896 KB
testcase_41 AC 82 ms
19,712 KB
testcase_42 AC 48 ms
16,384 KB
testcase_43 AC 132 ms
24,064 KB
testcase_44 AC 5 ms
5,376 KB
testcase_45 AC 17 ms
7,168 KB
testcase_46 AC 8 ms
5,376 KB
testcase_47 AC 4 ms
5,376 KB
testcase_48 AC 14 ms
6,784 KB
testcase_49 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <variant>

#define rep2(i, k, n) for (i64 i = (i64)(k); i < (i64)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) begin(x), end(x)
#ifdef ENV_LOCAL
#define dump \
  if (1) cerr
#else
#define dump \
  if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

// using namespace harudake;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 n;
  cin >> n;
  vector<pair<i64, i64>> vp;
  rep(i, 3) {
    i64 a, b;
    cin >> a >> b;
    vp.emplace_back(a, b);
  }
  i64 m = vp[0].first * vp[1].first * 2;
  vi64 dp1(m + 1);
  rep(i, 2) {
    rep(j, m + 1) {
      i64 jj = j + vp[i].first;
      if (jj > m) break;
      dp1[jj] = max(dp1[jj], dp1[j] + vp[i].second);
    }
  }
  rep(i, m) dp1[i + 1] = max(dp1[i + 1], dp1[i]);
  i64 mm = vp[0].first * vp[1].first;
  i64 ans = 0;
  rep(i, mm) {
    i64 rem = n - vp[2].first * i;
    if (rem < 0) break;
    i64 q = rem / mm;
    i64 r = rem % mm;
    // cerr << q << " " << r << endl;
    if (q == 0) {
      ans = max(ans, dp1[r] + vp[2].second * i);
      continue;
    }
    i64 triple = mm * vp[2].first;
    i64 diff = mm * vp[2].second - dp1[mm] * vp[2].first;
    // cerr << diff << endl;
    i64 x = q / vp[2].first;
    i64 rem2 = rem - triple * x;
    i64 q2 = rem2 / mm;
    // cerr << x << " " << rem2 << " " << q2 << endl;
    if (q2 == 0) {
      ans = max(ans, dp1[r] + x * mm * vp[2].second + vp[2].second * i);
      if (x > 0) {
        ans = max(ans, dp1[mm + r] + dp1[mm] * (vp[2].first - 1) +
                           (x - 1) * mm * vp[2].second + vp[2].second * i);
      }
    } else {
      ans = max(ans, dp1[mm + r] + dp1[mm] * (q2 - 1) + x * mm * vp[2].second +
                         vp[2].second * i);
    }
    ans = max(ans, dp1[r + mm] + dp1[mm] * (q - 1) + vp[2].second * i);
  }
  cout << ans << endl;
  return 0;
}
0