結果

問題 No.2227 King Kraken's Attack
コンテスト
ユーザー siman
提出日時 2023-02-27 18:36:37
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,207 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 926 ms
コンパイル使用メモリ 148,864 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-18 21:14:24
合計ジャッジ時間 8,066 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;

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

  ll ans = LLONG_MAX;

  for (ll a = 0; a <= H; ++a) {
    if (a * KA >= H * W) {
      ans = min(ans, a);
    } else {
      ll ok = H * W;
      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;
        }
      }

      ans = min(ans, a + ok);
    }
  }

  for (ll b = 0; b <= W; ++b) {
    if (b * KB >= H * W) {
      ans = min(ans, b);
    } else {
      ll ok = H * W;
      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;
        }
      }

      ans = min(ans, b + ok);
    }
  }

  cout << ans << endl;

  return 0;
}
0