結果

問題 No.3297 Bake Cookies
ユーザー おのせ
提出日時 2025-09-25 22:00:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,873 bytes
コンパイル時間 3,466 ms
コンパイル使用メモリ 253,556 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-25 22:01:03
合計ジャッジ時間 8,075 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#include <iostream>
#include <cmath>
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
using WGraph = vector<vector<pair<ll, ll>>>;
using mint = modint998244353;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
mt19937_64 rng(58);
long double PI = 3.14159265358979;
const ll LLMAX = 9223372036854775807;
const ll INF = 1e18;
vector<ll> di = {1, 0, -1, 0};
vector<ll> dj = {0, -1, 0, 1};
void chmin(ll& x, ll y) { x = min(x, y);};
void chmax(ll& x, ll y) { x = max(x, y);};

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

int main() {
    ll n, m, t;
    cin >> n >> m >> t;
    vector<ll> a(m);
    rep (i, m) {
        cin >> a[i];
        a[i]--;
    }

    ll ok = 1e15;
    ll ng = 0;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        auto f = [&](__int128 x) {
            vector<ll> ov(n, 0);
            ll cnt = 0;
            rep (i, m) {
                ll rest = x - ov[a[i]];
                if (rest > 0) ov[a[i]]++;
                else cnt++;
            }
            rep (i, n) {
                ll rest = x - ov[i];
                cnt -= rest / t; 
                if (cnt < 0) break;
            }
            return cnt <= 0;
        };
        if (f(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;
    return 0;
}
0