QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142369#1362. Bad PackingA3bat_team_f_Masr#WA 1ms5648kbC++14962b2023-08-19 00:38:162023-08-19 00:38:17

Judging History

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

  • [2023-08-19 00:38:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5648kb
  • [2023-08-19 00:38:16]
  • 提交

answer

#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
#define IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

const int N=1e5+5;
bool dp[1005][N],vis[1005][N];
int a[1005];
int mn,n,c;
bool solve(int id,int rem)
{

    if(id==n+1)return rem==0;
    bool &ret=dp[id][rem];
    if(vis[id][rem])return ret;
    vis[id][rem]=1;
    ret=solve(id+1,rem);
    if(rem>=a[id])ret|=solve(id+1,rem-a[id]);
    return ret;
}
int main()
{
    // IO
    cin>>n>>c;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    int sum=0;
    int mx=0;
    for(int i=0;i<=n;i++)
    {
        if(sum>c)break;
        mn=a[i];
        int tmp=c-sum;
        for(int j=0;j<mn;j++)
        {
            if(tmp-j<0)break;
            if(solve(i+1,tmp-j))mx=max(mx,j);
        }
        sum+=a[i];
    }
    cout<<c-mx;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5512kb

input:

4 10
9
6
5
7

output:

5

result:

ok single line: '5'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5648kb

input:

10 25
1
1
1
2
2
3
3
4
2
1

output:

25

result:

wrong answer 1st lines differ - expected: '20', found: '25'