結果

問題 No.3297 Bake Cookies
ユーザー Nichi10p
提出日時 2025-10-05 17:09:38
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 2,957 ms
コンパイル使用メモリ 278,380 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-05 17:09:48
合計ジャッジ時間 9,656 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define  rep(i,s,t) for (auto i=s; i != t; ++i)
#define rrep(i,s,t) for (auto i=t; i-- != s;)
typedef long long ll;
constexpr auto inf = numeric_limits<ll>::max();
constexpr bool chmin(auto &a, auto const &x) { return a > x ? a = x, true : false; }
constexpr bool chmax(auto &a, auto const &x) { return a < x ? a = x, true : false; }
// constexpr auto ascii_lowercase = "qwertyuiopasdfghjklzxcvbnm"sv;

int main() {
  int N, M, T;
  cin >> N >> M >> T;
  vector<int> Cnt(N);
  rep(_, 0, M) {
    int a;
    cin >> a;
    --a;
    Cnt[a] += 1;
  }

  auto f = [&](ll const t) -> bool {
    ll use=0;
    for (int const c : Cnt) {
      if (c <= t)
        use -= min<ll>((t - c) / T, M);
      else
        use += c - t;
    }
    return use <= 0;
  };

  ll ok=inf, ng=0;
  while (ok - ng > 1) {
    ll const m = midpoint(ok, ng);
    if (f(m))
      ok = m;
    else
      ng = m;
  }

  cout << ok << endl;
}
0