QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#825450#9778. Brotatoucup-team4435#TL 24ms8048kbC++233.1kb2024-12-21 19:27:502024-12-21 19:27:56

Judging History

This is the latest submission verdict.

  • [2024-12-21 19:27:56]
  • Judged
  • Verdict: TL
  • Time: 24ms
  • Memory: 8048kb
  • [2024-12-21 19:27:50]
  • Submitted

answer

#include "bits/stdc++.h"


#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

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

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

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}

const int INFi = 2e9;
const ll INF = 2e18;

void solve() {
    int n, k; cin >> n >> k;
    vector<ld> dp(n + 1);
    ld p; cin >> p;
    rep(i, n) dp[i] = INF;
    vector<ld> pwp(n + 1);
    pwp[0] = 1;
    for(int i = 1; i <= n; ++i) {
        pwp[i] = (pwp[i - 1]) * (1 - p);
    }
    const ld EPS = 1e-9;
    for(int t = 0; t <= k; ++t) {
        vector<ld> ndp(n + 1);
        ndp[n] = 0;
        for(int i = n; i >= 0; --i) {
            if (i < n) {
                ndp[i] = 1 + (1 - p) * ndp[i + 1] + p * dp[i];
            }
            // ndp[0] + 1 = 1 + ndp[i] * (1 - p)^{i} + p * (ndp[0] + 1) * (1 + (1 - p) + .. (1 - p)^{i-1})
            // ndp[0] + 1 = 1 + ndp[i] * (1 - p)^{i} + (ndp[0] + 1) * (1 - (1-p)^{i})
            // (ndp[0] + 1) * (1-p)^{i};
            // (ndp[0] + 1) * c = ndp[i] * pwp[i] + 1
            if (!i) break;
            ld e0 = (ndp[i] + (1 - pwp[i]) / (p * pwp[i]));
            if (i == 0 || e0 <= dp[i - 1]) {
                for(int j = i - 1; j >= 0; --j) {
                    ndp[j] = 1 + (1 - p) * ndp[j + 1] + p * e0;
                }
                assert(abs(ndp[0] - e0) / max<ld>(1, e0) < EPS);
                break;
            }
        }
        swap(dp, ndp);
        if (abs(n - dp[0]) <= EPS) {
            cout << (ld)n << '\n';
            return;
        }
    }
    cout << dp[0] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    int t = 1;
//    cin >> t;
    rep(i, t) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3876kb

input:

5 0
0.5

output:

62.000000000000

result:

ok found '62.000000000', expected '62.000000000', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

5 1
0.5

output:

47.000000000000

result:

ok found '47.000000000', expected '47.000000000', error '0.000000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3812kb

input:

10000 0
0.002

output:

247489700298.253686755896

result:

ok found '247489700298.253692627', expected '247489700298.253692627', error '0.000000000'

Test #4:

score: 0
Accepted
time: 3ms
memory: 8048kb

input:

100000 10
0.0002

output:

38767507133.232227981091

result:

ok found '38767507133.232231140', expected '38767507133.232215881', error '0.000000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 7972kb

input:

100000 0
0.0002

output:

2430683127170.376990795135

result:

ok found '2430683127170.376953125', expected '2430683127170.376953125', error '0.000000000'

Test #6:

score: 0
Accepted
time: 14ms
memory: 7976kb

input:

100000 20
0.0002

output:

801073272.231681398058

result:

ok found '801073272.231681347', expected '801073272.231680870', error '0.000000000'

Test #7:

score: 0
Accepted
time: 24ms
memory: 7964kb

input:

100000 40
0.0002

output:

478148.718426307409

result:

ok found '478148.718426307', expected '478148.718426307', error '0.000000000'

Test #8:

score: 0
Accepted
time: 6ms
memory: 7936kb

input:

99995 4
0.0001

output:

38976542.868175859934

result:

ok found '38976542.868175857', expected '38976542.868175834', error '0.000000000'

Test #9:

score: 0
Accepted
time: 3ms
memory: 7964kb

input:

99995 10
0.0001

output:

3549184.597712019549

result:

ok found '3549184.597712019', expected '3549184.597712017', error '0.000000000'

Test #10:

score: 0
Accepted
time: 12ms
memory: 7964kb

input:

99995 16
0.0001

output:

399507.470556742168

result:

ok found '399507.470556742', expected '399507.470556742', error '0.000000000'

Test #11:

score: 0
Accepted
time: 8ms
memory: 8040kb

input:

99990 8
0.0001

output:

7773463.947930723188

result:

ok found '7773463.947930723', expected '7773463.947930722', error '0.000000000'

Test #12:

score: 0
Accepted
time: 6ms
memory: 7988kb

input:

99990 10
0.0001

output:

3547428.945472297845

result:

ok found '3547428.945472298', expected '3547428.945472297', error '0.000000000'

Test #13:

score: 0
Accepted
time: 3ms
memory: 7976kb

input:

99990 12
0.0001

output:

1647102.020434396225

result:

ok found '1647102.020434396', expected '1647102.020434395', error '0.000000000'

Test #14:

score: 0
Accepted
time: 1ms
memory: 4212kb

input:

16664 1
0.0012

output:

257920044630.860549092293

result:

ok found '257920044630.860534668', expected '257920044630.860534668', error '0.000000000'

Test #15:

score: 0
Accepted
time: 3ms
memory: 4220kb

input:

16664 21
0.0012

output:

92190688.544415018492

result:

ok found '92190688.544415012', expected '92190688.544415027', error '0.000000000'

Test #16:

score: 0
Accepted
time: 4ms
memory: 4284kb

input:

16664 41
0.0012

output:

59865.091785919911

result:

ok found '59865.091785920', expected '59865.091785920', error '0.000000000'

Test #17:

score: 0
Accepted
time: 2ms
memory: 4216kb

input:

16659 5
0.0003

output:

63366.264406954761

result:

ok found '63366.264406955', expected '63366.264406955', error '0.000000000'

Test #18:

score: 0
Accepted
time: 2ms
memory: 4164kb

input:

16659 11
0.0003

output:

18120.911863542531

result:

ok found '18120.911863543', expected '18120.911863543', error '0.000000000'

Test #19:

score: 0
Accepted
time: 3ms
memory: 4192kb

input:

16659 17
0.0003

output:

16666.555451967406

result:

ok found '16666.555451967', expected '16666.555451967', error '0.000000000'

Test #20:

score: 0
Accepted
time: 2ms
memory: 4172kb

input:

16654 9
0.0001

output:

16656.079416575626

result:

ok found '16656.079416576', expected '16656.079416576', error '0.000000000'

Test #21:

score: 0
Accepted
time: 0ms
memory: 4220kb

input:

16654 11
0.0001

output:

16655.674122172401

result:

ok found '16655.674122172', expected '16655.674122172', error '0.000000000'

Test #22:

score: 0
Accepted
time: 2ms
memory: 4184kb

input:

16654 13
0.0001

output:

16655.665695362667

result:

ok found '16655.665695363', expected '16655.665695363', error '0.000000000'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

2774 2
0.0072

output:

28951389306.987514117733

result:

ok found '28951389306.987514496', expected '28951389306.987514496', error '0.000000000'

Test #24:

score: 0
Accepted
time: 1ms
memory: 4076kb

input:

2774 22
0.0072

output:

11312241.450653942030

result:

ok found '11312241.450653942', expected '11312241.450653942', error '0.000000000'

Test #25:

score: 0
Accepted
time: 1ms
memory: 4132kb

input:

2774 42
0.0072

output:

8222.415108508618

result:

ok found '8222.415108509', expected '8222.415108509', error '0.000000000'

Test #26:

score: 0
Accepted
time: 1ms
memory: 4068kb

input:

2769 6
0.0021

output:

13600.582355731611

result:

ok found '13600.582355732', expected '13600.582355732', error '0.000000000'

Test #27:

score: 0
Accepted
time: 1ms
memory: 4148kb

input:

2769 12
0.0021

output:

3239.549978211126

result:

ok found '3239.549978211', expected '3239.549978211', error '0.000000000'

Test #28:

score: 0
Accepted
time: 1ms
memory: 4132kb

input:

2769 18
0.0021

output:

2776.628194875240

result:

ok found '2776.628194875', expected '2776.628194875', error '0.000000000'

Test #29:

score: 0
Accepted
time: 1ms
memory: 4004kb

input:

2764 10
0.0007

output:

2765.987073955086

result:

ok found '2765.987073955', expected '2765.987073955', error '0.000000000'

Test #30:

score: 0
Accepted
time: 1ms
memory: 4000kb

input:

2764 12
0.0007

output:

2765.937362849972

result:

ok found '2765.937362850', expected '2765.937362850', error '0.000000000'

Test #31:

score: 0
Accepted
time: 1ms
memory: 4044kb

input:

2764 14
0.0007

output:

2765.936176703473

result:

ok found '2765.936176703', expected '2765.936176704', error '0.000000000'

Test #32:

score: -100
Time Limit Exceeded

input:

100000 1000000000
0.0001

output:


result: