QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#438066 | #8785. Fake Coin and Lying Scales | hos_lyric | AC ✓ | 59ms | 4192kb | C++14 | 2.6kb | 2024-06-10 05:56:27 | 2024-06-10 05:56:27 |
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 = 0;
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: 4080kb
input:
2 100 0 100 1
output:
109.8612289 105.9492059
result:
ok q=0 (2 test cases)
Test #2:
score: 0
Accepted
time: 4ms
memory: 4100kb
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.2241427 7.7636870 7.4430545 7.3186175 23.8793222 7.2872208 32.3673850 17.0907512 7.5806346 26.0954715 7.5310372 6.8798168 7.9494404 21.7042950 4.4533917 7.4567781 7.2046549 7.2176454 17.6384222 4.7621739 7.0690172 7.3979012 7.7603797 7.2362127 5.5910061 7.2131559 7.6674957 5.6390154 7.9931046 81....
result:
ok q=0 (10000 test cases)
Test #3:
score: 0
Accepted
time: 0ms
memory: 4192kb
input:
1 10000 0
output:
10986.1228867
result:
ok q=0 (1 test case)
Test #4:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 10000 10
output:
10905.6309124
result:
ok q=0 (1 test case)
Test #5:
score: 0
Accepted
time: 0ms
memory: 4112kb
input:
1 10000 100
output:
10365.7172672
result:
ok q=0 (1 test case)
Test #6:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 100000 0
output:
109861.2288668
result:
ok q=0 (1 test case)
Test #7:
score: 0
Accepted
time: 1ms
memory: 4096kb
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.6217029 858.0354114 802.3192044 87.7278966 525.7693819 840.9315829 644.1368196 704.7094898 508.0170395 127.5494108 261.9999736 726.1326894 126.3546401 532.0885465 7.6753950 344.1353643 722.6887354 349.3263530 145.7051413 728.6382545 626.0869731 837.6193990 228.9022790 411.6238170 288.9883913 132...
result:
ok q=0 (1000 test cases)
Test #8:
score: 0
Accepted
time: 1ms
memory: 4088kb
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:
10.0495131 9.1789531 7.6659979 8.2237095 9.6139874 9.5517415 8.5078160 9.7916108 9.7670486 7.1196356 9.4700880 9.5571932 9.9867598 8.1720326 7.9115930 9.5938649 9.6914015 8.6517945 14.4190825 9.6096658 9.5947902 9.7877460 7.8032283 9.7320679 7.9193151 8.6339090 8.8538123 6.3613025 7.6734355 8.673812...
result:
ok q=0 (1000 test cases)
Test #9:
score: 0
Accepted
time: 48ms
memory: 4192kb
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.2721347 21.7251971 20.8683965 21.2045564 20.7128845 21.2104116 353455.4194333 96659.8782814 21.5590544 7086.6337242 18.6887506 60920.4027335 188056.1807376 3074.9052899 555163.2554936 21.2524055 223401.2533363 23.9772448 165839.1673341 160146.4848991 20.8110855 21.5893845 183511.3705049 84477...
result:
ok q=0 (100000 test cases)
Test #10:
score: 0
Accepted
time: 52ms
memory: 4192kb
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.4134235 988105.0014244 579950.1050998 747487.2869415 820109.7136541 142607.8120981 1054350.1103368 504930.4348724 342767.8300322 451821.2786236 584224.5316629 812415.4508495 359187.7215332 521312.2301784 916726.2364707 930256.0937883 296061.6878160 796800.3109946 466533.2813266 807633.7432204...
result:
ok q=0 (100000 test cases)
Test #11:
score: 0
Accepted
time: 45ms
memory: 4176kb
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:
17.7660725 18.8601759 19.1093092 19.4239681 19.1316462 18.8465256 16.6852280 19.2770171 19.0195389 16.9607051 17.9216671 17.9095681 18.6686591 18.9567638 16.9267693 18.4892988 18.0533211 18.4844113 17.8260203 17.8441882 18.7380128 19.0356331 18.1052591 17.9429567 18.3192594 17.9821563 18.5743513 18....
result:
ok q=0 (100000 test cases)
Test #12:
score: 0
Accepted
time: 52ms
memory: 4112kb
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:
31.5566416 297865547.7323181 31.4337751 405381382.2439577 777499095.7845883 257440440.9180800 31.8963218 105964410.5193948 31.9876123 29.8657947 445375781.7126537 125531073.1478578 32.0518242 27488638.0522881 28988568.3134456 31.4987376 30.9558744 31.4443319 1733355.6817942 31.7240757 380877.1858181...
result:
ok q=0 (100000 test cases)
Test #13:
score: 0
Accepted
time: 53ms
memory: 4160kb
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.3344282 993406423.1046432 513220014.7735965 22380606.6597080 247854666.3819461 602319074.5355719 127217814.3740827 659736907.6092482 503607563.5039163 550220073.1782548 213873957.5933140 937815586.2116383 979331032.1014234 276465511.5320810 24.6745257 84653734.3791220 918166748.7395251 29...
result:
ok q=0 (100000 test cases)
Test #14:
score: 0
Accepted
time: 42ms
memory: 4092kb
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:
29.1845912 28.7103279 28.6471731 29.2126193 29.8161156 29.0645962 29.3547234 29.7510574 27.8275891 25.6847596 27.6010676 29.6475166 29.2104446 29.7865796 27.8439146 29.8085644 28.8650532 27.0592951 29.3637514 29.3757842 28.5015547 29.2795385 28.6417621 29.0275430 29.8230887 29.6119566 29.7622402 28....
result:
ok q=0 (100000 test cases)
Test #15:
score: 0
Accepted
time: 45ms
memory: 4112kb
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:
26.0191753 27.5581302 27.8169382 27.9676268 27.8929467 25.5482886 26.2960391 28.3156612 24.1744606 26.1116609 27.8762025 26.1071153 28.2653787 27.8441803 27.0910581 27.7679511 28.4602184 26.4195749 27.8417590 27.9195061 27.9647842 25.2624496 27.6541071 27.3874851 28.0601804 28.3239757 26.6401969 27....
result:
ok q=0 (100000 test cases)
Test #16:
score: 0
Accepted
time: 45ms
memory: 4000kb
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:
24.2751988 26.8720293 27.2725450 27.1801012 27.0347954 26.1926913 24.9814423 24.8829923 27.0058152 25.8738501 26.7269658 26.5113676 27.0523555 27.1147704 26.4000691 27.2877718 26.4478616 24.7675305 26.9030686 27.2848201 26.4705325 25.5214772 27.4619819 24.7586725 26.9513348 25.7498442 27.4133563 26....
result:
ok q=0 (100000 test cases)
Test #17:
score: 0
Accepted
time: 59ms
memory: 4056kb
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.3135162 79945807.5966198 896551040.3486234 539707003.6157255 695323400.8163120 42420667.3416423 877659783.8246890 650860090.8706021 949986390.1404984 80819167.1389431 652369973.8068242 272959465.7027783 468593092.3704293 570331670.1075866 421678376.5941188 381041977.9889351 166466182.815457...
result:
ok q=0 (100000 test cases)
Test #18:
score: 0
Accepted
time: 59ms
memory: 4076kb
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.1069750 953967306.9924152 89961615.1861741 243021911.2999512 231734299.5065258 779838670.8942574 344087281.3262265 313062773.4088859 1056036267.6450782 778672746.1148838 161650736.1284901 655912591.3817251 53755251.3252918 695233704.1203917 1096608984.2068284 117586485.9601999 267037674.92...
result:
ok q=0 (100000 test cases)
Test #19:
score: 0
Accepted
time: 55ms
memory: 4100kb
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.5820208 796226817.5022870 791081850.2214776 698496398.5906522 211203946.6896909 264138079.1507657 977355968.4372591 1060226382.8335551 712391733.9296737 724793.6094822 466038731.3723677 541124548.2992909 962399890.5278584 521396653.0085812 1019556750.6983199 711469336.3918110 477091393.100...
result:
ok q=0 (100000 test cases)
Test #20:
score: 0
Accepted
time: 59ms
memory: 4104kb
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.1299001 333276403.1310697 321783884.8593225 57835244.6417945 969769150.9485331 454690074.0638654 338523081.9526165 350856629.7037251 104498327.7244227 220643283.5490211 497726776.0370637 700751703.9785413 1076817274.7288525 796697082.6762199 755390747.1917241 1051941111.6366959 887573183....
result:
ok q=0 (100000 test cases)
Test #21:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 1000 1000000000
output:
25.4444453
result:
ok q=0 (1 test case)
Test #22:
score: 0
Accepted
time: 0ms
memory: 4116kb
input:
1 1 100000000
output:
20.6179053
result:
ok q=0 (1 test case)
Test #23:
score: 0
Accepted
time: 0ms
memory: 4164kb
input:
1 100 1000000000
output:
24.3090866
result:
ok q=0 (1 test case)
Test #24:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
1 1 1000000000
output:
22.9204904
result:
ok q=0 (1 test case)
Test #25:
score: 0
Accepted
time: 0ms
memory: 4128kb
input:
1 1000000000 1000000000
output:
32.3504118
result:
ok q=0 (1 test case)
Extra Test:
score: 0
Extra Test Passed