QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94705 | #5606. A Musical Question | PetroTarnavskyi# | AC ✓ | 42ms | 3688kb | C++17 | 1.0kb | 2023-04-07 15:47:00 | 2023-04-07 15:47:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 1047;
bitset<N> dp[2][N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int c, n;
cin >> c >> n;
VI v(n);
FOR (i, 0, n) cin >> v[i];
dp[0][0] = 1;
FOR(i, 0, n)
{
int b = (i + 1) % 2;
FOR (k, 0, c + 1)
{
if (k + v[i] <= c)
dp[b][k + v[i]] |= dp[b ^ 1][k];
dp[b][k] |= dp[b ^ 1][k] << v[i];
dp[b][k] |= dp[b ^ 1][k];
}
}
int a = -1, b = -1;
int k = n % 2;
FOR(i, 0, c + 1)
{
FOR(j, 0, i + 1)
{
if (dp[k][i][j])
{
if (a == -1 || ((a + b) < (i + j) || ((a + b == i + j) && a - b > i - j)))
a = i, b = j;
}
}
}
cout << a << ' ' << b << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3376kb
input:
100 5 10 20 40 60 85
output:
100 95
result:
ok single line: '100 95'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3416kb
input:
100 5 10 20 30 40 50
output:
80 70
result:
ok single line: '80 70'
Test #3:
score: 0
Accepted
time: 41ms
memory: 3592kb
input:
1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
500 500
result:
ok single line: '500 500'
Test #4:
score: 0
Accepted
time: 41ms
memory: 3600kb
input:
1000 1000 894 723 513 814 708 790 838 766 572 681 564 601 588 606 519 719 538 809 569 642 756 747 773 888 692 645 887 820 504 861 684 756 585 576 679 511 689 607 585 875 897 507 630 708 718 810 860 896 579 875 810 615 742 783 525 757 651 659 591 835 517 608 606 634 524 828 700 662 782 581 593 789 62...
output:
899 898
result:
ok single line: '899 898'
Test #5:
score: 0
Accepted
time: 35ms
memory: 3664kb
input:
999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1...
output:
0 0
result:
ok single line: '0 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
100 4 40 50 20 60
output:
90 80
result:
ok single line: '90 80'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3352kb
input:
50 50 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
output:
0 0
result:
ok single line: '0 0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
100 8 52 9 2 70 61 14 8 59
output:
83 81
result:
ok single line: '83 81'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
500 50 255 256 262 263 271 281 291 293 293 296 296 299 305 306 306 311 316 317 317 321 332 340 344 346 346 346 357 361 367 383 391 397 406 413 417 419 431 443 444 449 449 452 457 457 468 469 470 484 492 495
output:
495 492
result:
ok single line: '495 492'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3308kb
input:
20 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
10 10
result:
ok single line: '10 10'
Test #11:
score: 0
Accepted
time: 38ms
memory: 3592kb
input:
1000 1000 673 822 553 843 797 563 888 786 751 877 518 600 698 736 895 521 534 767 622 613 773 833 629 810 677 731 570 547 787 648 675 765 885 880 659 884 885 570 510 777 889 657 600 630 706 614 636 530 648 667 785 849 886 558 523 695 832 628 864 858 689 586 891 758 868 578 890 706 503 507 845 787 62...
output:
899 899
result:
ok single line: '899 899'
Test #12:
score: 0
Accepted
time: 42ms
memory: 3592kb
input:
1000 1000 807 757 556 591 611 690 763 542 559 839 708 771 553 869 642 585 658 580 816 769 544 713 732 708 857 747 587 855 885 532 892 703 667 622 734 610 871 807 624 881 569 872 584 755 543 502 513 837 538 530 630 699 787 833 730 739 538 547 657 723 558 673 735 796 790 724 825 646 865 754 859 871 75...
output:
899 899
result:
ok single line: '899 899'
Test #13:
score: 0
Accepted
time: 5ms
memory: 3580kb
input:
1000 50 34 40 28 47 44 27 28 30 31 27 45 47 31 49 30 47 44 43 30 43 26 37 43 40 48 44 43 45 47 40 31 32 25 42 43 27 37 45 26 39 28 30 42 35 44 29 44 36 49 34
output:
938 938
result:
ok single line: '938 938'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
1000 50 941 739 509 571 619 653 911 977 797 467 569 937 659 577 947 853 599 701 691 983 941 809 907 569 557 773 929 769 751 503 523 773 523 593 797 661 673 821 881 719 967 673 907 977 757 643 997 661 613 617
output:
997 990
result:
ok single line: '997 990'
Test #15:
score: 0
Accepted
time: 5ms
memory: 3568kb
input:
1000 50 863 863 599 887 599 719 691 709 487 631 557 503 883 967 593 853 521 641 521 677 827 739 593 683 593 941 811 853 877 853 673 587 863 659 971 557 577 661 461 743 743 509 503 503 479 499 971 887 617 919
output:
1000 996
result:
ok single line: '1000 996'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
500 50 269 263 257 251 257 263 251 257 27 257 263 27 269 263 263 269 263 269 27 27 263 27 257 257 263 263 251 269 257 251 27 27 27 257 251 251 263 27 269 257 251 269 251 27 27 263 251 269 263 269
output:
431 404
result:
ok single line: '431 404'
Test #17:
score: 0
Accepted
time: 3ms
memory: 3416kb
input:
90 50 15 255 31 511 511 15 127 127 255 255 511 31 15 31 127 15 127 511 127 127 31 511 63 15 15 31 63 511 511 63 511 511 511 63 15 255 511 15 255 63 31 511 255 255 31 127 127 511 15 255
output:
90 78
result:
ok single line: '90 78'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
654 25 511 63 31 255 511 255 63 255 15 31 15 63 255 31 127 255 15 511 31 63 255 255 127 127 127
output:
653 653
result:
ok single line: '653 653'
Test #19:
score: 0
Accepted
time: 8ms
memory: 3536kb
input:
511 250 459 441 441 467 275 377 324 314 419 449 227 219 209 230 314 208 459 208 413 265 467 324 458 298 329 475 275 439 209 458 307 458 227 324 419 275 377 434 449 298 377 329 321 459 324 275 344 230 459 265 434 324 237 324 475 458 439 413 219 329 275 449 307 467 324 203 203 265 298 324 275 329 321 ...
output:
510 510
result:
ok single line: '510 510'