結果

問題 No.2227 King Kraken's Attack
ユーザー simansiman
提出日時 2023-02-27 19:09:42
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 1,335 ms
コンパイル使用メモリ 141,280 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 09:48:55
合計ジャッジ時間 4,091 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 219 ms
6,944 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 123 ms
6,940 KB
testcase_21 AC 161 ms
6,940 KB
testcase_22 AC 9 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 78 ms
6,940 KB
testcase_25 AC 89 ms
6,944 KB
testcase_26 AC 154 ms
6,944 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 133 ms
6,944 KB
testcase_29 AC 125 ms
6,944 KB
testcase_30 AC 138 ms
6,944 KB
testcase_31 AC 123 ms
6,940 KB
testcase_32 AC 56 ms
6,940 KB
testcase_33 AC 49 ms
6,940 KB
testcase_34 AC 36 ms
6,944 KB
testcase_35 AC 60 ms
6,940 KB
testcase_36 AC 59 ms
6,940 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 3 ms
6,940 KB
testcase_41 AC 4 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 3 ms
6,940 KB
testcase_44 AC 3 ms
6,940 KB
testcase_45 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;
  
ll H, W, LA, LB, KA, KB;

bool f(ll a, ll b) {
  return H * W <= min(H, a * LA) * min(W, b * LB) + a * KA + b * KB;
}

int main() {
  cin >> H >> W >> LA >> LB >> KA >> KB;

  ll ans = LLONG_MAX;
  if (KA > 0) {
    ans = min(ans, (H * W + KA - 1) / KA);
  }
  if (KB > 0) {
    ans = min(ans, (H * W + KB - 1) / KB);
  }

  if (KA == 0 && KB == 0) {
    int a = (H + LA - 1) / LA;
    int b = (W + LB - 1) / LB;

    cout << a + b << endl;
    return 0;
  }

  for (ll a = 1; a <= H; ++a) {
    if (a * KA >= H * W) {
      ans = min(ans, a);
    } else {
      ll ok = H * W / (a * LA) + 1;
      ll ng = 0;

      while (abs(ok - ng) >= 2) {
        ll x = (ok + ng) / 2;
        ll cnt = min(H, a * LA) * min(W, x * LB) + a * KA + x * KB;

        if (cnt >= H * W) {
          ok = x;
        } else {
          ng = x;
        }
      }

      if (f(a, ok)) {
        ans = min(ans, a + ok);
      }
    }
  }

  for (ll b = 1; b <= W; ++b) {
    if (b * KB >= H * W) {
      ans = min(ans, b);
    } else {
      ll ok = H * W / (b * LB) + 1;
      ll ng = 0;

      while (abs(ok - ng) >= 2) {
        ll x = (ok + ng) / 2;
        ll cnt = min(H, x * LA) * min(W, b * LB) + x * KA + b * KB;

        if (cnt >= H * W) {
          ok = x;
        } else {
          ng = x;
        }
      }

      if (f(ok, b)) {
        ans = min(ans, b + ok);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0