QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#438058#8785. Fake Coin and Lying Scaleshos_lyricWA 27ms4272kbC++142.3kb2024-06-10 05:48:472024-06-10 05:48:48

Judging History

你现在查看的是最新测评结果

  • [2024-06-10 05:48:48]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:4272kb
  • [2024-06-10 05:48:47]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


/*
  (not a proof)
    fixed strategy: S \subseteq 3^N
    (coin <-> element of S)
    condition: for any x, #{ y \in S | dist(x, y) <= K } <= 3K+1
    {0,1} ~~> real weight p := S/3^N
    condition: p \sum[0<=i<=K] binom(N,i) 2^i <= 3K+1
    ans = (3K+1) / (\sum[0<=i<=K] binom(N,i) (1/3)^(N-i) (2/3)^i)
*/

constexpr double A = log(1.0L / 3.0L);
constexpr double B = log(2.0L / 3.0L);
double calc(Int N, Int i) {
  return lgamma(N + 1) - lgamma(i + 1) - lgamma(N - i + 1) + (N - i) * A + i * B;
}

// log(e^x + e^y)
double add(double x, double y) {
  if (x < y) swap(x, y);
  return x + log1p(exp(y - x));
}

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    Int N, K;
    scanf("%lld%lld", &N, &K);
    
    Int l = 0, r = K;
    chmax(l, N / 3 - 100);
    chmin(r, N / 3 + 100);
    double ans = calc(N, l);
    for (Int i = l + 1; i <= r; ++i) {
      ans = add(ans, calc(N, i));
    }
    ans = log((double)(3*K+1)) - ans;
    printf("%.7f\n", ans);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4160kb

input:

2
100 0
100 1

output:

109.8612289
105.9442183

result:

ok q=0 (2 test cases)

Test #2:

score: 0
Accepted
time: 27ms
memory: 4272kb

input:

10000
32 6
45 98
67 57
35 70
29 3
22 81
59 12
48 16
63 69
99 36
60 36
32 47
73 91
81 30
7 7
71 57
38 60
35 19
92 40
3 17
21 71
54 62
95 67
60 50
10 20
19 80
64 73
10 21
70 97
84 3
26 22
38 47
37 38
31 91
11 37
73 17
75 98
8 74
73 60
87 10
94 48
35 73
18 14
88 25
61 54
39 59
100 90
70 98
73 21
92 11
...

output:

20.1092516
5.6869754
5.1476818
5.3518581
23.8233447
5.4971682
32.2358590
16.8215706
5.3375381
25.7714114
6.4719387
4.9558271
5.6131281
21.3718668
3.0910425
5.1513126
5.1984970
6.5052398
17.1789547
3.9512437
5.3659760
5.2311086
5.5101750
5.0184466
4.1108739
5.4847969
5.3936275
4.1588831
5.6767538
81....

result:

ok q=0 (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 4056kb

input:

1
10000 0

output:

2456.6230720

result:

wrong answer WA (test case 1)