QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#438065 | #8785. Fake Coin and Lying Scales | hos_lyric | AC ✓ | 128ms | 4256kb | C++14 | 2.6kb | 2024-06-10 05:56:00 | 2024-06-10 05:56:01 |
Judging History
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 = 10;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
Int N, K;
scanf("%lld%lld", &N, &K);
const Int mid = N * 2 / 3;
Int l = 0, r = K;
if (r < mid) {
chmax(l, r - WIDTH);
} else if (l < mid) {
chmax(l, mid - WIDTH/2);
chmin(r, mid + 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;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4068kb
input:
2 100 0 100 1
output:
109.8612289 105.9442183
result:
ok q=0 (2 test cases)
Test #2:
score: 0
Accepted
time: 10ms
memory: 4176kb
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.7707806 5.3223442 5.4007679 23.8233447 5.5100610 32.2358590 16.8215706 5.4891026 25.7714114 6.4723061 4.9945201 5.8096568 21.3718668 3.0910425 5.3307908 5.2581056 6.5052414 17.1789562 3.9512437 5.3751309 5.3488945 5.6452278 5.1576622 4.1108908 5.4914302 5.5574192 4.1589000 5.8625180 81....
result:
ok q=0 (10000 test cases)
Test #3:
score: 0
Accepted
time: 0ms
memory: 4104kb
input:
1 10000 0
output:
10986.1228867
result:
ok q=0 (1 test case)
Test #4:
score: 0
Accepted
time: 0ms
memory: 4144kb
input:
1 10000 10
output:
10905.6304118
result:
ok q=0 (1 test case)
Test #5:
score: 0
Accepted
time: 0ms
memory: 4176kb
input:
1 10000 100
output:
10365.7122047
result:
ok q=0 (1 test case)
Test #6:
score: 0
Accepted
time: 0ms
memory: 4172kb
input:
1 100000 0
output:
109861.2288668
result:
ok q=0 (1 test case)
Test #7:
score: 0
Accepted
time: 2ms
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.7170072 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: 1ms
memory: 4176kb
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.9235259 7.2787804 6.3681872 6.7906412 7.4994074 7.4790947 6.6076433 7.6518272 7.7332494 6.0210233 7.6220145 7.4710339 7.9627208 6.2890505 5.8080888 7.6218298 7.7448522 6.4619099 13.8453428 7.6785856 7.4688029 7.6006807 5.8448406 7.6830612 5.8092386 7.5352967 6.8403203 5.2626902 5.9183887 7.8628820...
result:
ok q=0 (1000 test cases)
Test #9:
score: 0
Accepted
time: 119ms
memory: 4236kb
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 19.3273280 18.4705604 18.8067636 18.3150468 18.8125654 353455.3822170 96659.4674738 19.1611952 7085.3862667 16.3003184 60920.1005206 188056.0544847 3073.3096767 555163.1581744 18.8545589 223401.2219212 21.6826252 165839.0864891 160146.1266307 18.4134216 19.1915181 183511.0621007 84476...
result:
ok q=0 (100000 test cases)
Test #10:
score: 0
Accepted
time: 113ms
memory: 4160kb
input:
100000 740599 913 947030 8115 575926 9039 721122 7094 794424 8453 157723 6263 973352 1890 462079 302 333631 3870 435636 4238 572643 7448 775859 6119 343386 2778 486927 1883 880553 7918 878758 5150 274829 778 759586 5734 461205 6806 744940 1346 378522 4830 214767 1511 367452 9987 288068 9685 761467 1...
output:
805982.4128062 988104.9970935 579950.0970954 747487.2819615 820109.7082621 142607.7912062 1054350.1093636 504930.4345453 342767.8241471 451821.2736996 584224.5250522 812415.4468669 359187.7174469 521312.2282355 916726.2319236 930256.0908364 296061.6863956 796800.3071843 466533.2738094 807633.7423149...
result:
ok q=0 (100000 test cases)
Test #11:
score: 0
Accepted
time: 114ms
memory: 4228kb
input:
100000 3460 249080 4870 627106 7714 639325 6245 973410 5156 799724 2143 932101 3190 88015 5691 880401 4405 773261 157 516968 1022 535321 7679 193074 2293 754309 6302 607322 9422 65236 7327 352879 2188 417324 3181 532778 8804 165866 2433 321295 4829 557456 7228 613548 470 947610 2867 326654 1091 7711...
output:
15.3746536 16.4668874 16.7143253 17.0296690 16.7381049 16.4590607 14.2943549 16.8830684 16.6267351 14.6942645 15.5455392 15.5145984 16.2805161 16.5624323 14.5312591 16.0944684 15.6656431 16.0935580 15.4306773 15.4555023 16.3447657 16.6408447 15.7540770 15.5528776 15.9417694 15.5870180 16.1811892 16....
result:
ok q=0 (100000 test cases)
Test #12:
score: 0
Accepted
time: 121ms
memory: 4188kb
input:
100000 485911443 648621499 967545108 273118575 544774196 541753568 572826636 56596285 997351031 75012282 841305005 238445153 871651103 680174033 831928615 349267999 895576242 735170120 38669405 423897783 879163052 156607422 474161410 146955978 703868457 884260985 882781563 482183053 774752914 414027...
output:
29.1587458 297865547.5133527 29.0358796 405381382.1875811 777499095.7430742 257440440.6977308 29.4984269 105964410.0702813 29.5897175 27.4679000 445375781.5979491 125531072.8935303 29.6539294 27488637.1351739 28988567.4626364 29.1008418 28.5579796 29.0464368 1733353.8359320 29.3261804 380875.1830918...
result:
ok q=0 (100000 test cases)
Test #13:
score: 0
Accepted
time: 126ms
memory: 4164kb
input:
100000 998709247 6662353 938409567 5496364 470262254 388552 44631553 8053900 263812189 8140673 570847244 3686835 143527865 6364614 630983298 5151426 508843717 9845212 529080317 4866307 229185417 7424168 870671276 2477533 922155225 4868463 286532330 7131107 5469824 6272182 112064124 9288326 871839242...
output:
1052557876.3310647 993406423.1016930 513220014.7731830 22380606.5430695 247854666.3658979 602319074.5323163 127217814.3506085 659736907.6051240 503607563.4940023 550220073.1736026 213873957.5764332 937815586.2102104 979331032.0987661 276465511.5192375 22.2766345 84653734.3328819 918166748.7360917 29...
result:
ok q=0 (100000 test cases)
Test #14:
score: 0
Accepted
time: 115ms
memory: 4172kb
input:
100000 2388237 863104141 1949853 594471487 5788570 323905636 6626472 532884672 6478027 985480511 8713369 400770447 7877963 563355387 8572690 802705946 246447 691673591 1048191 39348128 9822372 87353076 4622806 985586908 3940664 689517333 7206000 907183324 7647553 126209541 9304319 816108273 3026286 ...
output:
26.7867053 26.3124441 26.2492818 26.8147274 27.4182238 26.6667035 26.9568310 27.3531648 25.4297852 23.2868858 25.2031746 27.2496262 26.8125551 27.3886874 25.4460223 27.4106716 26.4671653 24.6615286 26.9658604 26.9778916 26.1036681 26.8816470 26.2438758 26.6296502 27.4251965 27.2140663 27.3643473 26....
result:
ok q=0 (100000 test cases)
Test #15:
score: 0
Accepted
time: 114ms
memory: 4176kb
input:
100000 3230 990083111 447677 391972657 692146 408354973 191509 902573102 662501 450354073 721550 41375394 457751 109724688 636199 701346721 4329 135209393 7190 728002830 562092 480808431 608393 78791345 751611 613615532 576135 459945713 830181 180428675 549685 436319534 608642 828570290 40757 416064...
output:
23.6282210 25.1602852 25.4190754 25.5698490 25.4950853 23.1504245 23.8981930 25.9178013 21.7817507 23.7168899 25.4783473 23.7092570 25.8675134 25.4463241 24.6931899 25.3700968 26.0623601 24.0222316 25.4438893 25.5216352 25.5669691 22.8646580 25.2563015 24.9898050 25.6623353 25.9261291 24.2433684 25....
result:
ok q=0 (100000 test cases)
Test #16:
score: 0
Accepted
time: 114ms
memory: 4196kb
input:
100000 25834 61214455 26648 808954129 93315 645258548 40846 889138139 50931 688595112 83574 231579050 4476 298005500 10230 178645104 67274 582026639 45478 228216795 31799 640547396 76931 331956048 42831 764190687 32200 938076217 11303 774768820 48548 908303551 52646 376587760 30951 91507236 32097 76...
output:
21.8781740 24.4749780 24.8748908 24.7827566 24.6373418 23.7950652 22.5885625 22.4872943 24.6082543 23.4764494 24.3297778 24.1137648 24.6549855 24.7175736 24.0041624 24.8903398 24.0503936 22.3703619 24.5058742 24.8872209 24.0730276 23.1243039 25.0643616 22.3611786 24.5537864 23.3594749 25.0157545 24....
result:
ok q=0 (100000 test cases)
Test #17:
score: 0
Accepted
time: 128ms
memory: 4164kb
input:
100000 274227737 68346059 218685007 54356465 989024364 38654736 621112634 30460344 744276614 23921662 244777456 92571767 802238000 396401 867445410 73326922 915786289 8870270 283682509 84172313 874633287 75201041 511367562 84949073 634359016 56041772 732833967 55417420 693037815 93779223 439536157 2...
output:
99920321.1320138 79945807.4158297 896551040.3280770 539707003.5896020 695323400.7995684 42420666.9790939 877659783.8244418 650860090.8233335 949986390.1355960 80819166.9020208 652369973.7586480 272959465.5978538 468593092.3207638 570331670.0658230 421678376.5126417 381041977.9624977 166466182.788143...
result:
ok q=0 (100000 test cases)
Test #18:
score: 0
Accepted
time: 122ms
memory: 4132kb
input:
100000 145675394 9644 868401983 5079 81959359 7252 221259510 4525 210940342 503 709938567 8322 313226886 2026 284975389 1034 961263243 1271 708878403 8424 147154537 1117 597142707 9049 49009960 8469 632841549 912 998250617 5932 107131683 9999 243110679 3650 921083825 3103 645636937 7805 803218474 41...
output:
159931663.1069418 953967306.9924122 89961615.1861298 243021911.2999410 231734299.5065246 779838670.8942516 344087281.3262233 313062773.4088841 1056036267.6450775 778672746.1148778 161650736.1284864 655912591.3817174 53755251.3252053 695233704.1203910 1096608984.2068255 117586485.9601532 267037674.92...
result:
ok q=0 (100000 test cases)
Test #19:
score: 0
Accepted
time: 127ms
memory: 4156kb
input:
100000 415903859 143863 726725861 220923 721402153 142794 636365369 56467 195687608 492519 244711303 612418 892437244 320712 965738323 66085 653139241 592706 2885567 920921 430945805 947767 493265196 74615 877041778 105313 477250612 324587 932782139 573227 651591411 492931 438774413 597150 816745072...
output:
455527059.5818477 796226817.5021349 791081850.2213787 698496398.5906079 211203946.6884286 264138079.1495105 977355968.4370793 1060226382.8335209 712391733.9292194 724793.3424221 466038731.3712651 541124548.2992152 962399890.5277983 521396653.0082409 1019556750.6980124 711469336.3914324 477091393.099...
result:
ok q=0 (100000 test cases)
Test #20:
score: 0
Accepted
time: 127ms
memory: 4160kb
input:
100000 932735028 38475 303723723 37217 293643065 82693 53306635 90174 883367937 63149 414476477 62827 308746443 66010 319864936 52981 95584375 56035 201651629 95614 453621071 58910 638222297 35431 980668234 47930 725614760 41170 688105374 50896 958291243 76312 808245100 31656 617265859 68228 8643946...
output:
1024260600.1298795 333276403.1310084 321783884.8591817 57835244.6409469 969769150.9484973 454690074.0637895 338523081.9525095 350856629.7036422 104498327.7241293 220643283.5487839 497726776.0369987 700751703.9785135 1076817274.7288280 796697082.6761916 755390747.1916871 1051941111.6366560 887573183....
result:
ok q=0 (100000 test cases)
Test #21:
score: 0
Accepted
time: 0ms
memory: 4172kb
input:
1 1000 1000000000
output:
23.0687361
result:
ok q=0 (1 test case)
Test #22:
score: 0
Accepted
time: 0ms
memory: 4256kb
input:
1 1 100000000
output:
19.5192930
result:
ok q=0 (1 test case)
Test #23:
score: 0
Accepted
time: 0ms
memory: 4164kb
input:
1 100 1000000000
output:
22.1082716
result:
ok q=0 (1 test case)
Test #24:
score: 0
Accepted
time: 0ms
memory: 4256kb
input:
1 1 1000000000
output:
21.8218781
result:
ok q=0 (1 test case)
Test #25:
score: 0
Accepted
time: 0ms
memory: 4164kb
input:
1 1000000000 1000000000
output:
29.9525155
result:
ok q=0 (1 test case)
Extra Test:
score: 0
Extra Test Passed