QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#447894 | #8785. Fake Coin and Lying Scales | lichenghan | WA | 144ms | 4152kb | C++14 | 1.2kb | 2024-06-18 23:46:08 | 2024-06-18 23:46:09 |
Judging History
answer
#include <bits/stdc++.h>
#define dbg(...) (fprintf(stderr,##__VA_ARGS__),fflush(stderr))
#define dputs(str) dbg(str "\n")
using namespace std;
double add_ln(double x,double y){
if(x>y) swap(x,y);
if(x-y>=30) return x;
return y+log(exp(x-y)+1);
}
double fact(int x){
return (x+0.5)*log(x);
}
double binom(int u,int d){
if(d==0||d==u) return 0;
return fact(u)-fact(d)-fact(u-d)-1;
}
long long n,k;
void solve(){
scanf("%lld%lld",&n,&k);
if(k==0){
printf("%.20lf\n",n*log(3));
return;
}
double bot=log(3*k+1);
if(k>=n) return (void) printf("%.20lf\n",bot);
double ans=log(3)*n+bot;
double div=0;
for(int i=0;i<=40&&i<=k;i++){
div=add_ln(div,binom(n,k-i)+log(2)*(k-i));
}
ans-=div;
// printf("%.20lf %.20lf\n",bot,ans);
printf("%.20lf\n",max(bot,ans));
}
void test(){
auto exact_binom=[&](int n,int k){
double ans=0;
for(int i=n;i>=n-k+1;i--) ans+=log(i);
for(int i=k;i>=1;i--) ans-=log(i);
return ans;
};
// const int n=40,k=20;
const int n=1e6,k=5e5;
printf("%+.4lf\n",exact_binom(n,k)-binom(n,k));
}
int main(){
// test(); return 0;
int tc;
scanf("%d",&tc);
while(tc--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4100kb
input:
2 100 0 100 1
output:
109.86122886681097554629 105.93924719644667220564
result:
ok q=0 (2 test cases)
Test #2:
score: 0
Accepted
time: 10ms
memory: 4108kb
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.17550472840905939620 5.68697535633982020897 5.22425612812880046931 5.35185813347606664792 23.87554244816926285466 5.49716822529320214841 32.30953256311723009730 16.89647190708933521819 5.33753807970131788352 25.84965944883099098206 6.54868881371174893502 4.95582705760126085437 5.61312810638807047...
result:
ok q=0 (10000 test cases)
Test #3:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
1 10000 0
output:
10986.12288668109795253258
result:
ok q=0 (1 test case)
Test #4:
score: 0
Accepted
time: 0ms
memory: 4128kb
input:
1 10000 10
output:
10905.70314224009234749246
result:
ok q=0 (1 test case)
Test #5:
score: 0
Accepted
time: 0ms
memory: 4108kb
input:
1 10000 100
output:
10365.79243269461585441604
result:
ok q=0 (1 test case)
Test #6:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
1 100000 0
output:
109861.22886681098316330463
result:
ok q=0 (1 test case)
Test #7:
score: 0
Accepted
time: 2ms
memory: 4140kb
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.67742305327146823402 858.09744631217154164915 802.37745033272483397013 87.66692411933394168955 525.80141522928352060262 840.98119062977195881103 644.19835861722071967961 704.77484816969160874578 508.03299522924714892724 127.58403606787584294580 262.05549168787490543764 726.18999142393033707776 1...
result:
ok q=0 (1000 test cases)
Test #8:
score: 0
Accepted
time: 1ms
memory: 4152kb
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.74022952476318160109 7.23921497377980571741 6.36818718635049219046 6.79009723551390464991 7.32580750259577317962 7.34923082461333443405 6.56807791141197583329 7.45529848568329089886 7.62851762657505538812 6.02102334934952665435 7.59287028784481776711 7.32974968904151236160 7.86748856869912849277 6...
result:
ok q=0 (1000 test cases)
Test #9:
score: -100
Wrong Answer
time: 144ms
memory: 4132kb
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.25061139423632994294 239557.68543059215880930424 14.27737742334962689483 14.88820622691749839817 14.10850623816470594818 14.52645001308146355257 353455.46327571361325681210 96659.54852849862072616816 14.72074721808731823103 7085.43977071030531078577 14.63703820035290092960 60920.1815806163358...
result:
wrong answer WA (test case 2)