QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#545776#6355. 5lifanTL 1994ms8644kbC++141.3kb2024-09-03 17:11:042024-09-03 17:11:04

Judging History

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

  • [2024-09-03 17:11:04]
  • 评测
  • 测评结果:TL
  • 用时:1994ms
  • 内存:8644kb
  • [2024-09-03 17:11:04]
  • 提交

answer

// 
/*
感觉对于一个T而言符合要求的k应该是一段区间
如果这样是对的,那么可以对于每个T求得最少元素个数和最大元素个数
其实也就是例如min:
f[i,j]=min(f[i-1,j],f[i-1,j-a[j]]+1)
g[i,j]=max(g[i-1,j],g[i-1,j-a[j]]+1)
然后这东西怎么优化,感觉有凸性
注意到S与n同级,说明只有O(sqrt n) 个不同的数
那就多重背包
*/
#include<bits/stdc++.h>
using namespace std;
#define N 205000
#define M 801
int f[2][N],g[2][N],S,n,m,q[N],h,t,c[205050];
#define pr pair<int,int>
#define mk make_pair
int a[N];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>S;
    for(int i=1;i<=n;++i)cin>>a[i];
    sort(a+1,a+n+1);
    memset(f,0x3f,sizeof f);
    memset(g,-0x3f,sizeof g);
    f[0][0]=g[0][0]=0;
    for(int i=1;i<=n;++i){
        int s=i&1,t=s^1;
        for(int j=0;j<=S;++j){
            f[s][j]=f[t][j];
            if(j>=a[i])f[s][j]=min(f[s][j],f[t][j-a[i]]+1);
        }
    }
    for(int i=1;i<=n;++i){
        int s=i&1,t=s^1;
        for(int j=0;j<=S;++j){
            g[s][j]=g[t][j];
            if(j>=a[i])g[s][j]=max(g[s][j],g[t][j-a[i]]+1);
        }
    }
    long long res=0;
    for(int j=0;j<=S;++j)res+=max(0,g[n&1][j]-f[n&1][j]+1);
    cout<<res<<"\n";
}

详细

Test #1:

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

input:

7 9
0 0 0 1 1 2 5

output:

42

result:

ok 1 number(s): "42"

Test #2:

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

input:

10 33
9 9 8 1 1 1 1 1 1 1

output:

48

result:

ok 1 number(s): "48"

Test #3:

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

input:

10 14
2 4 4 1 0 1 0 1 0 1

output:

81

result:

ok 1 number(s): "81"

Test #4:

score: 0
Accepted
time: 2ms
memory: 7736kb

input:

10 14
3 5 3 0 1 0 1 0 1 0

output:

87

result:

ok 1 number(s): "87"

Test #5:

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

input:

40 50
1 1 1 1 3 3 0 3 1 1 0 0 2 1 0 0 1 0 0 2 7 1 2 1 3 0 2 2 3 1 1 0 0 2 0 1 1 0 1 1

output:

1067

result:

ok 1 number(s): "1067"

Test #6:

score: 0
Accepted
time: 0ms
memory: 7444kb

input:

1200 1000
1 1 2 3 0 1 0 0 1 1 0 2 3 0 1 2 0 0 1 0 4 1 1 2 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 1 2 0 4 0 3 1 6 0 1 1 0 0 0 0 4 0 0 0 0 0 0 1 0 0 1 7 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 3 0 1 0 1 0 0 1 1 2 2 0 1 1 0 0 1 4 1 2 0 0 0 3 0 0 2 1 0 2 0 0 0 1 1 0 0 2 0 0 0 0 1 1 0 1 0 1 6 1 1 ...

output:

737899

result:

ok 1 number(s): "737899"

Test #7:

score: 0
Accepted
time: 224ms
memory: 8644kb

input:

12000 10000
1 1 0 0 1 0 2 1 3 0 0 1 0 3 1 1 0 1 1 1 1 1 2 1 0 1 2 1 0 1 2 0 5 1 1 1 0 2 0 1 0 1 0 3 2 0 1 0 1 1 2 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 4 0 1 3 1 0 0 1 0 1 2 1 0 0 1 1 0 2 1 1 0 1 0 1 0 0 2 1 1 3 0 1 1 1 0 0 0 1 1 1 0 3 0 0 0 2 0 0 0 1 0 2 0 1 1 1 0 0 1 0 1 0 2 0 0 0 0 0 0 0 1 0 1 0 0 4 1 ...

output:

73685347

result:

ok 1 number(s): "73685347"

Test #8:

score: 0
Accepted
time: 1994ms
memory: 7568kb

input:

36000 30000
0 3 4 1 2 1 1 0 0 1 1 0 1 0 2 1 0 0 0 0 2 1 0 2 0 0 0 0 0 1 1 4 1 4 0 0 2 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 3 1 1 1 0 0 0 0 0 0 1 2 0 2 3 0 0 0 0 3 1 0 0 0 1 0 1 2 0 0 2 0 1 0 0 2 1 1 0 3 1 6 0 0 1 1 2 0 1 2 0 0 1 0 1 1 0 0 1 0 0 0 1 0 2 0 1 1 1 0 0 5 2 0 5 1 0 0 0 0 1 1 1 8 0 1 1 0 1 ...

output:

658813003

result:

ok 1 number(s): "658813003"

Test #9:

score: -100
Time Limit Exceeded

input:

200000 200000
0 1 1 1 1 1 0 1 0 3 1 0 0 1 1 0 1 1 1 2 3 0 1 0 1 0 2 5 0 1 1 4 1 1 0 0 0 0 0 0 2 1 0 0 2 1 1 2 0 3 0 1 3 0 1 1 1 0 1 0 1 2 0 1 1 0 0 2 2 1 0 1 1 2 4 1 0 2 0 5 1 2 0 0 1 0 2 3 1 0 1 1 1 1 0 0 0 5 1 0 0 1 2 1 1 0 0 0 1 0 0 1 2 1 0 0 2 1 2 3 0 0 3 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 ...

output:


result: