QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#221138#5606. A Musical Questionricky0129WA 39ms128540kbC++171.5kb2023-10-21 10:01:462023-10-21 10:01:46

Judging History

你现在查看的是最新测评结果

  • [2023-10-21 10:01:46]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:128540kb
  • [2023-10-21 10:01:46]
  • 提交

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);

  sort(A.begin(), A.end());
  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]];
      bs temp = dp[i-1][j];
      temp = temp << A[i];
      dp[i][j] |= temp;
    }
  }
  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: 1ms
memory: 3544kb

input:

100 5
10 20 40 60 85

output:

100 95

result:

ok single line: '100 95'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

100 5
10 20 30 40 50

output:

80 70

result:

ok single line: '80 70'

Test #3:

score: 0
Accepted
time: 39ms
memory: 128540kb

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: 36ms
memory: 128444kb

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 501

result:

wrong answer 1st lines differ - expected: '899 898', found: '899 501'