QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#221132 | #5606. A Musical Question | ricky0129 | WA | 41ms | 128624kb | C++14 | 1.4kb | 2023-10-21 09:57:12 | 2023-10-21 09:57:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define FOR(i,n) for(int i=0;i<n;i++)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
const int MOD = (int)1e9+7;
typedef bitset<1001> bs;
int main()
{
int c, n; cin>>c>>n;
vi B(n);
FOR(i,n) cin>>B[i];
vi A;
for(int x: B)
if(x<=c) A.pb(x);
n = A.size();
if(n==0) {
cout<<"0 0\n";
return 0;
}
vector<vector<bs>> dp(n, vector<bs>(c+1));
dp[0][0][A[0]] = 1;
dp[0][A[0]][0] = 1;
for(int i=1;i<n;i++) {
for(int j=0;j<=c;j++) {
dp[i][j] |= dp[i-1][j];
if(j>=A[i]) dp[i][j] |= dp[i-1][j-A[i]];
dp[i][j] |= (dp[i-1][j] << A[i]);
}
}
pii best = make_pair(0,0);
for(int i=0;i<=c;i++) {
for(int j=0;j<=c;j++) {
if(dp[n-1][i][j]) {
assert(dp[n-1][i][j] == dp[n-1][j][i]);
int s1 = best.f + best.s;
int d1 = abs(best.f - best.s);
int s2 = i + j;
int d2 = abs(i-j);
if(s1 < s2) {
best = make_pair(i, j);
}
else if(s1==s2 && d1 > d2) {
best = make_pair(i, j);
}
}
}
}
cout<<max(best.f, best.s)<<" "<<min(best.f, best.s)<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: 3672kb
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: 128624kb
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: -100
Wrong Answer
time: 40ms
memory: 128624kb
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 894
result:
wrong answer 1st lines differ - expected: '899 898', found: '899 894'