結果

問題 No.3297 Bake Cookies
ユーザー Kanato Sugano
提出日時 2025-10-05 14:17:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 2,682 bytes
コンパイル時間 3,604 ms
コンパイル使用メモリ 257,760 KB
実行使用メモリ 17,272 KB
最終ジャッジ日時 2025-10-05 14:17:49
合計ジャッジ時間 6,866 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <atcoder/all>
#include <ranges>
using namespace atcoder;

/* alias */
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

/* define short */
#define pb push_back
#define mp make_pair
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool)        \
  if (bool) {              \
    cout << "YES" << endl; \
  } else {                 \
    cout << "NO" << endl;  \
  }
#define yesno(bool)        \
  if (bool) {              \
    cout << "yes" << endl; \
  } else {                 \
    cout << "no" << endl;  \
  }
#define YesNo(bool)        \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

/* REP macro */
#define rep(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define reps(i, a, n) for (ll i = (a); i <= (ll)(n); ++i)

template <typename T>
inline bool chmax(T& a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 座標を表す構造体
struct Point {
  int y, x;

  // コンストラクタを追加
  Point(int y_ = 0, int x_ = 0) : y(y_), x(x_) {}

  // <
  bool operator<(const Point& other) const {
    if (y != other.y)
      return y < other.y;
    return x < other.x;
  }

  // == 一致確認
  bool operator==(const Point& other) const {
    return y == other.y && x == other.x;
  }
};

/*statement*/
bool flag = true;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, m, t;
  cin >> n >> m >> t;
  vi a;
  vi oven(n, 0);
  rep(i, 0, m) {
    int input;
    cin >> input;
    a.pb(input);
    oven[input - 1]++;
  }

  multimap<ll, ll> oven_map;
  for (auto u : oven)
    oven_map.insert(mp(u, u));

  while (oven_map.begin()->first + t < prev(oven_map.end())->second) {
    ll top_time = oven_map.begin()->first;
    ll top_num = oven_map.begin()->second;
    ll last_time = oven_map.rbegin()->first;
    ll last_num = oven_map.rbegin()->second;

    ll diff = (last_time - top_time - 1) / t;
    top_time += diff * t;
    top_num += diff;
    last_time -= diff;
    last_num -= diff;
    oven_map.erase(oven_map.begin());
    oven_map.erase(--oven_map.end());
    oven_map.insert(mp(top_time, top_num));
    oven_map.insert(mp(last_time, last_num));
  }

  ll ans_max=0;
  for(auto u:oven_map) chmax(ans_max,u.first);
  cout << ans_max << endl;
  return 0;
}
0