QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791724 | #2629. Let's Win the Election | thangthang | 16 | 725ms | 9388kb | C++20 | 2.9kb | 2024-11-28 20:34:42 | 2024-11-28 20:34:42 |
Judging History
answer
// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 5e2 + 5;
const int mod = 1e9 + 7;
int n, k;
pair <int, int> state[N];
namespace subtask1{
const int sub = 105;
using lb = long double;
const lb inf = 1e9;
lb dp[sub][sub][sub];
void solve(){
lb ans = inf;
for (int fix = 0; fix < k; ++ fix){
for (int i = 0; i <= fix; ++ i){
for (int j = 0; j <= k - fix; ++ j) dp[0][i][j] = inf;
}
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++ i){
lb a = state[i].se, b = state[i].fi;
for (int j = 0; j <= fix; ++ j){
for (int t = 0; t <= k - fix; ++ t){
dp[i][j][t] = dp[i - 1][j][t];
if (t) dp[i][j][t] = min(dp[i][j][t], dp[i - 1][j][t - 1] + a / (fix + 1));
if (j && b != -1) dp[i][j][t] = min(dp[i][j][t], dp[i - 1][j - 1][t] + b / j);
}
}
}
ans = min(ans, dp[n][fix][k - fix]);
}
cout << fixed << setprecision(10) << ans;
}
}
namespace ac{
using lb = long double;
const lb inf = 1e9;
lb dp[N][N];
void solve(){
lb ans = inf;
for (int fix = 0; fix < k; ++ fix){
for (int i = 0; i <= n; ++ i)
for (int j = 0; j <= k; ++ j) dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 1; i <= n; ++ i){
lb a = state[i].se, b = state[i].fi;
for (int j = 0; j <= min(k, i); ++ j){
if (j <= fix){
if (j < fix) dp[i][j] = dp[i - 1][j] + a / (fix + 1);
if (j && state[i].fi != mod) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + b / j);
if (j == fix) dp[i][i] = min(dp[i][i], dp[i][j]);
}
}
else {
dp[i][j] = min({dp[i][j], dp[i - 1][j], dp[i - 1][j - 1] + a / (fix + 1)});
}
}
}
ans = min(ans, dp[n][k]);
}
cout << fixed << setprecision(10) << ans;
}
}
void solve(){
cin >> n >> k;
for (int i = 1; i <= n; ++ i){
cin >> state[i].se >> state[i].fi;
if (state[i].fi == -1) state[i].fi = mod;
}
sort(state + 1, state + n + 1);
ac::solve();
//if (n <= 100) subtask1::solve();
//else ac::solve();
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 3840kb
input:
1 1 729 -1
output:
729.0000000000
result:
ok error = 0.000000000
Test #2:
score: 5
Accepted
time: 0ms
memory: 3880kb
input:
2 2 204 -1 96 -1
output:
300.0000000000
result:
ok error = 0.000000000
Test #3:
score: 5
Accepted
time: 0ms
memory: 3856kb
input:
3 2 639 -1 597 -1 543 -1
output:
1140.0000000000
result:
ok error = 0.000000000
Test #4:
score: 5
Accepted
time: 1ms
memory: 3848kb
input:
4 3 765 -1 121 -1 409 -1 529 -1
output:
1059.0000000000
result:
ok error = 0.000000000
Test #5:
score: 5
Accepted
time: 10ms
memory: 8448kb
input:
500 50 16 -1 224 -1 562 -1 783 -1 830 -1 455 -1 744 -1 170 -1 196 -1 89 -1 80 -1 357 -1 400 -1 443 -1 690 -1 732 -1 705 -1 735 -1 776 -1 820 -1 992 -1 811 -1 690 -1 364 -1 148 -1 246 -1 535 -1 184 -1 951 -1 86 -1 324 -1 2 -1 842 -1 386 -1 55 -1 571 -1 840 -1 689 -1 538 -1 287 -1 310 -1 322 -1 471 -1...
output:
2580.0000000000
result:
ok error = 0.000000000
Test #6:
score: 5
Accepted
time: 46ms
memory: 7792kb
input:
500 125 567 -1 27 -1 102 -1 783 -1 52 -1 120 -1 732 -1 300 -1 193 -1 772 -1 829 -1 109 -1 699 -1 215 -1 392 -1 193 -1 400 -1 260 -1 559 -1 855 -1 974 -1 935 -1 507 -1 773 -1 481 -1 539 -1 369 -1 588 -1 593 -1 922 -1 28 -1 278 -1 553 -1 525 -1 140 -1 845 -1 637 -1 107 -1 641 -1 130 -1 514 -1 104 -1 9...
output:
15729.0000000000
result:
ok error = 0.000000000
Test #7:
score: 5
Accepted
time: 176ms
memory: 8620kb
input:
500 250 76 -1 295 -1 438 -1 389 -1 573 -1 937 -1 359 -1 81 -1 881 -1 565 -1 620 -1 275 -1 52 -1 572 -1 446 -1 942 -1 338 -1 684 -1 657 -1 616 -1 156 -1 648 -1 492 -1 168 -1 711 -1 348 -1 715 -1 868 -1 29 -1 509 -1 483 -1 658 -1 183 -1 214 -1 733 -1 566 -1 388 -1 962 -1 850 -1 44 -1 191 -1 743 -1 143...
output:
66687.0000000000
result:
ok error = 0.000000000
Test #8:
score: 5
Accepted
time: 352ms
memory: 9088kb
input:
500 375 565 -1 295 -1 459 -1 572 -1 658 -1 810 -1 178 -1 13 -1 644 -1 975 -1 150 -1 220 -1 557 -1 156 -1 573 -1 543 -1 325 -1 62 -1 427 -1 599 -1 204 -1 6 -1 892 -1 590 -1 801 -1 338 -1 367 -1 311 -1 890 -1 172 -1 606 -1 300 -1 806 -1 150 -1 814 -1 97 -1 712 -1 769 -1 583 -1 792 -1 24 -1 384 -1 136 ...
output:
147876.0000000000
result:
ok error = 0.000000000
Test #9:
score: 5
Accepted
time: 545ms
memory: 8568kb
input:
500 500 187 -1 429 -1 984 -1 572 -1 718 -1 162 -1 355 -1 922 -1 180 -1 457 -1 881 -1 946 -1 105 -1 273 -1 3 -1 891 -1 290 -1 281 -1 598 -1 432 -1 279 -1 471 -1 123 -1 212 -1 290 -1 975 -1 796 -1 438 -1 43 -1 371 -1 229 -1 121 -1 912 -1 317 -1 41 -1 445 -1 307 -1 777 -1 336 -1 320 -1 699 -1 617 -1 23...
output:
249562.0000000000
result:
ok error = 0.000000000
Test #10:
score: 5
Accepted
time: 310ms
memory: 9388kb
input:
500 350 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000 -1 1000...
output:
350000.0000000000
result:
ok error = 0.000000000
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 5
Accepted
time: 0ms
memory: 3904kb
input:
1 1 791 791
output:
791.0000000000
result:
ok error = 0.000000000
Test #12:
score: 5
Accepted
time: 91ms
memory: 8132kb
input:
500 150 824 824 524 524 20 20 713 713 668 668 342 342 53 53 660 660 180 180 614 614 504 504 216 216 200 200 551 551 660 660 696 696 194 194 820 820 517 517 209 209 484 484 744 744 904 904 268 268 931 931 265 265 701 701 511 511 591 591 443 443 374 374 296 296 848 848 481 481 771 771 521 521 687 687 ...
output:
341.0793145790
result:
ok error = 0.000000000
Test #13:
score: 0
Wrong Answer
time: 82ms
memory: 8652kb
input:
500 150 187 -1 798 798 819 819 927 927 9 -1 742 742 268 -1 453 -1 132 132 947 947 683 -1 156 -1 809 -1 681 -1 472 472 656 -1 177 177 347 347 102 102 45 45 215 -1 580 580 371 371 807 807 625 625 11 11 596 596 34 -1 803 803 360 360 45 -1 613 613 490 -1 871 -1 974 -1 710 -1 308 308 698 -1 117 117 962 -...
output:
355.9601652030
result:
wrong answer read 355.960165203 but expected 355.342286415, error = 0.617878788
Subtask #3:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 0ms
memory: 3900kb
input:
7 1 309 988 195 951 51 -1 104 279 498 906 410 498 76 -1
output:
104.0000000000
result:
wrong answer read 104.000000000 but expected 51.000000000, error = 53.000000000
Subtask #4:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 0ms
memory: 3920kb
input:
20 3 43 487 143 720 123 886 88 266 639 739 129 522 300 696 88 889 276 550 653 722 92 157 85 674 452 666 290 517 780 801 49 430 633 932 197 421 20 749 286 479
output:
155.0000000000
result:
wrong answer read 155.000000000 but expected 112.000000000, error = 43.000000000
Subtask #5:
score: 0
Wrong Answer
Test #61:
score: 0
Wrong Answer
time: 1ms
memory: 4316kb
input:
100 15 824 961 637 866 334 751 463 701 28 953 68 168 589 741 107 298 690 754 20 869 686 990 151 659 90 234 279 477 210 337 481 626 347 916 428 580 445 708 239 584 306 495 932 978 84 896 39 199 498 609 308 668 301 605 275 664 426 444 220 345 429 488 365 698 364 681 57 156 129 824 166 931 412 855 745 ...
output:
327.0000000000
result:
wrong answer read 327.000000000 but expected 324.333333333, error = 2.666666667
Subtask #6:
score: 11
Accepted
Test #81:
score: 11
Accepted
time: 719ms
memory: 8544kb
input:
500 500 215 315 169 657 849 974 865 984 799 919 681 905 236 828 612 980 342 741 203 235 955 997 456 691 358 1000 617 965 691 912 10 295 426 646 72 725 242 788 171 742 256 696 157 347 151 397 229 798 323 427 133 368 833 993 266 525 254 915 371 438 700 889 235 654 400 953 52 277 31 562 15 298 244 383 ...
output:
1767.1975007973
result:
ok error = 0.000000000
Test #82:
score: 11
Accepted
time: 724ms
memory: 8140kb
input:
500 500 205 643 330 716 239 703 264 305 223 429 319 806 279 764 538 850 908 938 357 944 583 968 376 927 593 597 882 947 249 254 770 794 231 553 215 518 448 887 699 964 484 538 314 583 565 648 342 703 554 869 667 814 264 953 269 902 292 546 234 943 375 705 488 637 238 933 363 466 532 966 233 738 637 ...
output:
2763.3815674113
result:
ok error = 0.000000000
Test #83:
score: 11
Accepted
time: 720ms
memory: 8772kb
input:
500 500 621 820 492 921 496 917 602 719 670 831 533 828 616 764 790 923 907 994 732 854 428 715 448 485 666 970 695 959 446 865 552 582 556 670 421 569 576 871 696 793 618 982 484 838 558 680 475 601 657 890 452 795 639 864 640 967 821 995 489 937 922 990 623 868 444 719 401 887 442 690 403 822 444 ...
output:
3763.0435188736
result:
ok error = 0.000000000
Test #84:
score: 11
Accepted
time: 717ms
memory: 8508kb
input:
500 500 806 904 712 941 724 822 850 985 844 899 910 932 705 835 715 907 727 895 659 703 839 887 819 828 772 785 723 774 680 872 726 928 690 797 770 891 673 884 836 857 728 973 630 963 816 967 865 972 627 918 651 695 652 843 799 929 779 795 885 974 807 854 707 991 786 914 678 805 682 785 859 864 649 ...
output:
4840.5411729334
result:
ok error = 0.000000000
Test #85:
score: 11
Accepted
time: 724ms
memory: 8840kb
input:
500 500 801 849 901 999 849 921 925 999 864 992 851 989 907 967 853 923 840 912 816 877 853 878 825 893 909 992 824 914 854 902 961 981 871 905 812 985 800 981 902 998 943 991 818 967 899 999 811 878 815 968 919 990 896 994 805 870 833 892 809 895 850 982 863 984 828 850 835 953 860 973 825 876 896 ...
output:
5820.4909981528
result:
ok error = 0.000000000
Test #86:
score: 11
Accepted
time: 725ms
memory: 8436kb
input:
500 500 298 693 393 595 298 660 327 678 293 668 374 585 369 629 346 615 319 702 308 678 333 708 335 656 274 748 333 709 368 665 289 707 315 635 338 623 262 777 304 740 281 742 266 695 314 712 271 752 308 655 304 665 298 677 326 665 328 701 268 716 307 737 247 736 248 702 322 669 361 603 282 736 317 ...
output:
3946.9244817827
result:
ok error = 0.000000000
Test #87:
score: 11
Accepted
time: 719ms
memory: 7944kb
input:
500 500 431 590 318 561 389 581 897 976 980 980 659 799 431 641 517 675 732 800 688 810 891 960 685 779 464 686 464 607 831 874 205 517 932 1000 555 719 666 758 306 546 593 752 257 550 923 968 839 907 932 979 422 579 865 865 941 977 499 692 618 789 628 793 630 766 655 761 931 991 482 617 638 786 663...
output:
3878.5527203058
result:
ok error = 0.000000000
Subtask #7:
score: 0
Wrong Answer
Test #88:
score: 23
Accepted
time: 8ms
memory: 8792kb
input:
500 50 170 253 450 885 684 995 425 830 76 273 249 856 188 360 410 635 457 765 184 217 364 807 74 675 504 883 768 975 714 814 222 922 144 940 704 878 780 949 256 325 113 997 436 692 683 812 154 655 227 816 666 750 645 940 537 579 267 671 474 972 188 403 65 459 606 671 375 495 590 722 238 998 157 790 ...
output:
368.1297619048
result:
ok error = 0.000000000
Test #89:
score: 0
Wrong Answer
time: 8ms
memory: 8500kb
input:
500 50 621 709 721 966 896 937 884 911 865 993 714 915 736 840 740 753 615 796 717 976 825 872 622 788 955 964 903 983 882 972 643 797 648 826 648 855 784 839 871 935 683 813 885 968 706 707 636 844 896 933 737 743 629 909 905 936 688 957 712 767 972 983 678 900 633 731 683 985 843 987 689 835 812 9...
output:
2882.6169127473
result:
wrong answer read 2882.616912747 but expected 2882.474582304, error = 0.142330443