QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#438063 | #8785. Fake Coin and Lying Scales | hos_lyric | AC ✓ | 735ms | 4260kb | C++14 | 2.6kb | 2024-06-10 05:52:15 | 2024-06-10 05:52:17 |
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 = 100;
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: 4172kb
input:
2 100 0 100 1
output:
109.8612289 105.9442183
result:
ok q=0 (2 test cases)
Test #2:
score: 0
Accepted
time: 33ms
memory: 4160kb
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: 0ms
memory: 4164kb
input:
1 10000 0
output:
10986.1228867
result:
ok q=0 (1 test case)
Test #4:
score: 0
Accepted
time: 0ms
memory: 4196kb
input:
1 10000 10
output:
10905.6304118
result:
ok q=0 (1 test case)
Test #5:
score: 0
Accepted
time: 0ms
memory: 4168kb
input:
1 10000 100
output:
10365.7122047
result:
ok q=0 (1 test case)
Test #6:
score: 0
Accepted
time: 0ms
memory: 4116kb
input:
1 100000 0
output:
109861.2288668
result:
ok q=0 (1 test case)
Test #7:
score: 0
Accepted
time: 4ms
memory: 4152kb
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: 4256kb
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.1944054 13.8453316 7.6285176 7.2855065 7.3356340 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: 0
Accepted
time: 735ms
memory: 4232kb
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 17.1123016 16.2582972 16.5981202 16.1026530 16.5994619 353455.3822170 96659.4674674 16.9469983 7085.3587083 14.6650478 60920.1005202 188056.0544847 3073.1899851 555163.1581744 16.6414120 223401.2219212 20.2641497 165839.0864891 160146.1266288 16.2154797 16.9767117 183511.0621003 84476...
result:
ok q=0 (100000 test cases)
Test #10:
score: 0
Accepted
time: 716ms
memory: 4132kb
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: 716ms
memory: 4260kb
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:
13.5952422 14.5808266 14.7186379 15.0798393 14.8365118 14.8646988 12.5435375 14.9558551 14.7696829 14.2543492 14.2900314 13.5198809 14.6577900 14.6104779 12.4987781 14.1092547 14.0625008 14.3437568 13.4100310 13.8090264 14.4612091 14.6584704 14.8603117 13.8417464 14.6553807 13.5806682 14.3027799 14....
result:
ok q=0 (100000 test cases)
Test #12:
score: 0
Accepted
time: 733ms
memory: 4228kb
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:
26.9415244 297865547.5133527 26.8186579 405381382.1875811 777499095.7430742 257440440.6977308 27.2812038 105964410.0702674 27.3724943 25.2507236 445375781.5979491 125531072.8935302 27.4367067 27488637.1314154 28988567.4604104 26.8836188 26.3407596 26.8292148 1733353.5483195 27.1089617 380874.6948959...
result:
ok q=0 (100000 test cases)
Test #13:
score: 0
Accepted
time: 731ms
memory: 4224kb
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 20.0597548 84653734.3328819 918166748.7360917 29...
result:
ok q=0 (100000 test cases)
Test #14:
score: 0
Accepted
time: 720ms
memory: 4252kb
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:
24.5702712 24.0961878 24.0323830 24.5977874 25.2012903 24.4496952 24.7398456 25.1361600 23.2202048 21.0714623 22.9861417 25.0328097 24.5958093 25.1717244 23.2290441 25.1936494 24.2505645 22.4550700 24.7489951 24.7608852 23.8871766 24.6647424 24.0274014 24.4126327 25.2082239 24.9972614 25.1473168 24....
result:
ok q=0 (100000 test cases)
Test #15:
score: 0
Accepted
time: 707ms
memory: 4132kb
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:
21.8731840 22.9472744 23.2045778 23.3624526 23.2807096 20.9358158 21.6850896 23.7035432 19.9301709 21.7356930 23.2644798 21.4951344 23.6528001 23.2323749 22.4782392 23.1563050 23.8482362 21.8505032 23.2288162 23.3064543 23.3564648 20.6561171 23.0465842 22.7905242 23.4493206 23.7129877 22.1125598 23....
result:
ok q=0 (100000 test cases)
Test #16:
score: 0
Accepted
time: 712ms
memory: 4260kb
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:
19.7319345 22.3266398 22.6777519 22.6109284 22.4566649 21.6002459 20.7269958 20.4413487 22.4188006 21.3000767 22.1705540 21.9208602 22.4810955 22.5576406 21.9430541 22.7114272 21.8685427 20.2126901 22.3461275 22.6946129 21.8881534 20.9662575 22.8700132 20.1772106 22.3653564 21.6340778 22.8229357 21....
result:
ok q=0 (100000 test cases)
Test #17:
score: 0
Accepted
time: 727ms
memory: 4256kb
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.9790919 877659783.8244418 650860090.8233335 949986390.1355960 80819166.9020207 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: 721ms
memory: 4172kb
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: 732ms
memory: 4164kb
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.3424220 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: 723ms
memory: 4228kb
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: 1ms
memory: 4168kb
input:
1 1000 1000000000
output:
21.8225754
result:
ok q=0 (1 test case)
Test #22:
score: 0
Accepted
time: 0ms
memory: 4140kb
input:
1 1 100000000
output:
19.5192930
result:
ok q=0 (1 test case)
Test #23:
score: 0
Accepted
time: 0ms
memory: 4136kb
input:
1 100 1000000000
output:
21.8218781
result:
ok q=0 (1 test case)
Test #24:
score: 0
Accepted
time: 0ms
memory: 4152kb
input:
1 1 1000000000
output:
21.8218781
result:
ok q=0 (1 test case)
Test #25:
score: 0
Accepted
time: 0ms
memory: 4160kb
input:
1 1000000000 1000000000
output:
27.7352919
result:
ok q=0 (1 test case)
Extra Test:
score: 0
Extra Test Passed