結果

問題 No.2390 Udon Coupon (Hard)
ユーザー そすうぽよそすうぽよ
提出日時 2023-07-21 22:34:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,967 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 207,324 KB
実行使用メモリ 59,492 KB
最終ジャッジ日時 2023-10-21 22:33:29
合計ジャッジ時間 5,123 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 55 ms
37,732 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 23 ms
14,788 KB
testcase_25 AC 22 ms
14,984 KB
testcase_26 AC 26 ms
15,248 KB
testcase_27 AC 26 ms
15,248 KB
testcase_28 AC 22 ms
13,468 KB
testcase_29 AC 81 ms
33,908 KB
testcase_30 WA -
testcase_31 AC 83 ms
33,644 KB
testcase_32 AC 86 ms
33,380 KB
testcase_33 AC 80 ms
32,392 KB
testcase_34 AC 215 ms
59,492 KB
testcase_35 AC 148 ms
56,392 KB
testcase_36 AC 197 ms
54,876 KB
testcase_37 AC 150 ms
57,908 KB
testcase_38 AC 187 ms
56,920 KB
testcase_39 AC 10 ms
13,732 KB
testcase_40 AC 23 ms
16,832 KB
testcase_41 AC 35 ms
19,600 KB
testcase_42 AC 24 ms
16,304 KB
testcase_43 AC 43 ms
23,952 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 9 ms
7,072 KB
testcase_46 AC 5 ms
4,764 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 9 ms
6,612 KB
testcase_49 AC 2 ms
4,348 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;
    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;
    if (diff > 0) {
      i64 x = q / vp[2].first;
      i64 rem2 = rem - triple * x;
      i64 q2 = rem2 / mm;
      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 +
                             (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);
      }
    } else {
      ans = max(ans, dp1[r + mm] + dp1[mm] * (q - 1) + vp[2].second * i);
    }
  }
  cout << ans << endl;
  return 0;
}
0