QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#438062#8785. Fake Coin and Lying Scaleshos_lyricWA 736ms4224kbC++142.6kb2024-06-10 05:51:202024-06-10 05:51:20

Judging History

This is the latest submission verdict.

  • [2024-06-10 05:51:20]
  • Judged
  • Verdict: WA
  • Time: 736ms
  • Memory: 4224kb
  • [2024-06-10 05:51:20]
  • Submitted

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));
}

constexpr int WIDTH = 100;

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;
    if (r < N/3) {
      chmax(l, r - WIDTH);
    } else if (l < N/3) {
      chmax(l, N/3 - WIDTH/2);
      chmin(r, N/3 + WIDTH/2);
    } else {
      chmin(r, l + WIDTH);
    }
// cerr<<"l = "<<l<<", r = "<<r<<endl;
    assert(0 <= l); assert(l <= r); assert(r <= K);
    assert(r - l <= WIDTH);
    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: 4196kb

input:

2
100 0
100 1

output:

109.8612289
105.9442183

result:

ok q=0 (2 test cases)

Test #2:

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

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: 0
Accepted
time: 1ms
memory: 4152kb

input:

1
10000 0

output:

10986.1228867

result:

ok q=0 (1 test case)

Test #4:

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

input:

1
10000 10

output:

10905.6304118

result:

ok q=0 (1 test case)

Test #5:

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

input:

1
10000 100

output:

10365.7122047

result:

ok q=0 (1 test case)

Test #6:

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

input:

1
100000 0

output:

109861.2288668

result:

ok q=0 (1 test case)

Test #7:

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

input:

1000
867 38
906 28
876 34
182 38
692 59
986 55
675 20
699 12
741 82
154 11
264 6
682 4
176 19
728 69
37 95
501 56
998 96
495 52
359 86
750 19
726 39
794 6
268 16
609 70
414 45
182 19
123 68
909 56
880 71
419 8
679 14
363 16
751 35
299 73
852 35
901 36
903 63
425 85
416 33
80 89
863 91
491 32
603 84
...

output:

777.5985603
858.0193656
802.2988451
87.5881847
525.7217786
840.9016501
644.1214706
704.7007372
507.9529648
127.5106198
261.9883462
726.1297418
126.2928677
532.0349065
5.6559918
344.0706165
722.6341505
349.2660926
145.5349540
728.6252007
626.0582436
837.6155919
228.8702179
411.5568834
288.9257568
132...

result:

ok q=0 (1000 test cases)

Test #8:

score: 0
Accepted
time: 5ms
memory: 4180kb

input:

1000
71 766
31 464
8 194
12 296
69 506
55 518
31 237
73 576
50 685
1 137
29 661
58 508
46 870
33 172
66 94
41 634
38 725
94 163
94 45
34 685
71 486
95 511
37 108
54 643
64 94
1 624
48 283
1 64
23 122
3 866
52 798
68 669
43 460
68 187
50 403
31 877
100 191
44 512
33 50
91 732
37 584
22 501
46 93
81 7...

output:

7.7402295
7.2392150
6.3681872
6.7900972
7.3258075
7.3492308
6.5680779
7.4552985
7.6285176
6.0210233
7.5928703
7.3297497
7.8674886
6.2480429
5.6454469
7.5511869
7.6852436
6.1944099
13.8453316
7.6285176
7.2855065
7.3356454
5.7838252
7.5652753
5.6454469
7.5352967
6.7452363
5.2626902
5.9053618
7.8628820...

result:

ok q=0 (1000 test cases)

Test #9:

score: -100
Wrong Answer
time: 736ms
memory: 4224kb

input:

100000
448906 73251
858780 829062
380117 529011
219451 974416
390411 446812
457769 678634
440286 29979
663948 267273
623318 824172
557346 329036
2366 757990
279231 95725
394222 75586
671713 417299
997686 156089
462641 704003
267172 15563
115033 76151
271539 36507
909436 341831
97232 987703
780566 75...

output:

242700.1695511
198372.4412114
87777.8801126
50656.0366777
90155.2194343
105719.6413222
353455.3822170
153355.4319486
143969.9276742
128725.2620320
498.9459707
64465.4823855
188056.0544847
155150.4411365
555163.1581744
106845.3542123
223401.2219212
26527.5066407
165839.0864891
210076.0667359
22417.55...

result:

wrong answer WA (test case 2)