結果

問題 No.3318 客に卵をかける
コンテスト
ユーザー Kude
提出日時 2025-11-01 00:26:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 3,322 ms
コンパイル使用メモリ 298,240 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-01 00:26:21
合計ジャッジ時間 4,798 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    ll n, x, y, p, q, r;
    cin >> n >> x >> y >> p >> q >> r;
    auto f = [&](ll cnt) -> long double {
      ll t = x + cnt * y;
      if (t == 1) return q;
      ll rest = n - cnt;
      auto g = [&](ll k) {
        // q (1+(1-1/t)+(1-/t)^2+...+(1-1/t)^(k-1))
        // = pq (1-(1-1/t)^k)
        long double res = -expm1l(k * log1pl(-1.0L/t)) * t * q;
        res += (rest - k) * (long double)(__int128(t) * q - r) / t;
        return res;
      };
      ll l = -1, r = rest + 1;
      while (r - l > 2) {
        ll c = (l + r) / 2;
        if (g(c) < g(c+1)) l = c;
        else r = c + 1;
      }
      return p * cnt + g(l + 1);
    };
    {
      ll l = -1, r = n + 1;
      while (r - l > 2) {
        ll c = (l + r) / 2;
        if (f(c) < f(c+1)) l = c;
        else r = c + 1;
      }
      cout << fixed << setprecision(12) << f(l + 1) << '\n';
    }
  }
}
0