QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101915 | #6355. 5 | zhouhuanyi | TL | 4443ms | 42508kb | C++11 | 1.8kb | 2023-05-01 21:11:02 | 2023-05-01 21:12:04 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N 400000
#define inf 1e9
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int n,S,cnt,cnt2,a[N+1],cnts[N+1];
long long ans;
vector<int>dp[N+1];
vector<int>A[N+1];
vector<int>B[N+1];
vector<int>c;
vector<int>operator + (vector<int>a,vector<int>b)
{
c.clear();
for (int i=0;i<b.size();++i) a.push_back(b[i]);
sort(a.begin(),a.end());
for (int i=0;i<a.size();++i)
{
while (c.size()>=2&&a[i]-c[(int)(c.size())-2]<=cnt2) c.pop_back();
c.push_back(a[i]);
}
return c;
}
vector<int>operator + (vector<int>p,int d)
{
for (int i=0;i<p.size();++i) p[i]+=d;
return p;
}
vector<int>operator - (vector<int>p,int d)
{
for (int i=0;i<p.size();++i) p[i]-=d;
return p;
}
int main()
{
int d,sr;
n=read(),S=read();
for (int i=1;i<=n;++i)
{
a[i]=read()-1;
if (a[i]==-1) cnt++;
if (a[i]==0) cnt2++;
if (a[i]>=1) cnts[a[i]]++;
}
for (int i=0;i<=cnt;++i) dp[i].push_back(cnt-i);
for (int i=1;i<=S;++i)
if (cnts[i])
{
for (int j=0;j<i;++j)
{
d=(S+cnt-j)/i;
for (int k=0;k<=d;++k)
{
if (!k||k/cnts[i]!=(k-1)/cnts[i]) A[k]=dp[k*i+j]-k;
else A[k]=A[k-1]+(dp[k*i+j]-k);
}
for (int k=d;k>=0;--k)
{
if (k==d||k/cnts[i]!=(k+1)/cnts[i]) B[k]=dp[k*i+j]-k;
else B[k]=B[k+1]+(dp[k*i+j]-k);
}
for (int k=0;k<=d;++k)
{
dp[k*i+j]=A[k]+k;
if (k>=cnts[i]) dp[k*i+j]=dp[k*i+j]+(B[k-cnts[i]]+k);
}
}
}
for (int i=0;i<=S+cnt;++i)
{
sr=-inf;
for (int j=0;j<dp[i].size();++j) ans+=dp[i][j]+cnt2-max(dp[i][j],sr+1)+1,sr=dp[i][j]+cnt2;
}
printf("%lld\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 33968kb
input:
7 9 0 0 0 1 1 2 5
output:
42
result:
ok 1 number(s): "42"
Test #2:
score: 0
Accepted
time: 4ms
memory: 33164kb
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: 7ms
memory: 34428kb
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: 13ms
memory: 33252kb
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: 2ms
memory: 33060kb
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: 3ms
memory: 32944kb
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: 32ms
memory: 35188kb
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: 92ms
memory: 35424kb
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: 0
Accepted
time: 900ms
memory: 42508kb
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:
23477878007
result:
ok 1 number(s): "23477878007"
Test #10:
score: 0
Accepted
time: 1020ms
memory: 38480kb
input:
140000 200000 0 1 3 0 0 0 0 0 1 1 1 1 4 1 1 8 1 1 0 3 0 0 0 1 5 0 1 1 0 4 1 0 2 1 0 0 1 1 1 0 2 4 0 2 0 3 0 2 1 2 1 2 1 1 1 2 1 0 0 1 1 1 1 0 1 0 9 1 5 1 1 4 0 1 1 4 1 1 1 1 3 1 1 1 1 4 1 1 0 3 1 0 1 3 1 1 3 1 1 3 4 1 1 0 0 1 1 0 1 4 1 1 1 1 0 1 1 0 0 2 0 6 5 1 1 3 2 4 0 1 4 1 1 1 1 2 0 0 2 1 5 1 1 ...
output:
15405328745
result:
ok 1 number(s): "15405328745"
Test #11:
score: 0
Accepted
time: 1466ms
memory: 38544kb
input:
90000 200000 3 1 1 1 4 5 1 1 1 1 10 1 3 2 1 1 7 8 1 1 8 5 1 1 6 1 1 1 0 1 4 5 0 5 1 21 1 4 0 2 4 3 1 6 7 3 1 1 1 0 1 2 5 1 1 1 1 2 0 8 0 1 2 4 0 0 11 1 2 2 2 1 28 0 1 1 2 1 2 1 11 1 5 9 1 1 1 1 1 2 1 1 1 1 2 1 0 4 1 1 2 1 1 1 4 1 5 1 1 5 4 1 5 1 0 1 1 1 1 0 1 2 4 1 1 1 1 1 1 1 1 1 2 1 1 3 1 2 1 1 0 ...
output:
9895248405
result:
ok 1 number(s): "9895248405"
Test #12:
score: 0
Accepted
time: 1775ms
memory: 38056kb
input:
80000 200000 1 5 1 1 1 3 1 0 3 11 1 5 1 2 1 21 4 13 1 1 1 1 0 1 1 1 2 1 13 2 1 4 5 0 1 1 6 3 1 1 1 1 1 1 8 1 1 6 3 1 1 1 1 8 1 2 0 1 1 1 1 1 1 1 17 1 1 1 6 1 1 1 11 1 15 5 1 1 1 1 1 2 8 0 0 1 1 2 3 14 1 1 3 18 1 1 1 3 1 1 1 1 1 1 4 0 9 1 0 1 1 1 0 4 1 2 1 1 3 2 3 21 3 2 11 1 1 0 1 29 1 1 2 1 5 6 1 5...
output:
8980751457
result:
ok 1 number(s): "8980751457"
Test #13:
score: 0
Accepted
time: 2127ms
memory: 38100kb
input:
70000 200000 4 0 0 2 5 1 0 1 4 1 1 1 1 3 12 1 1 1 0 1 1 6 5 1 1 1 1 1 0 1 1 1 16 1 1 1 1 1 10 1 2 1 1 0 1 7 1 0 3 3 1 1 1 1 2 2 1 1 7 1 1 2 1 1 1 1 14 1 6 1 1 12 1 1 1 1 1 1 1 7 1 1 1 7 1 1 1 1 2 1 0 1 13 1 0 1 1 1 3 1 3 1 0 1 4 1 1 1 1 3 1 13 0 1 1 7 0 0 1 1 12 3 1 1 3 1 1 1 6 1 1 1 1 1 1 1 1 10 1 ...
output:
8196878191
result:
ok 1 number(s): "8196878191"
Test #14:
score: 0
Accepted
time: 2818ms
memory: 38192kb
input:
60000 200000 1 1 1 1 25 1 4 1 1 1 1 1 10 2 12 1 1 1 1 1 12 7 3 1 3 1 1 1 1 1 1 1 1 1 1 1 1 2 1 12 1 1 1 1 0 1 1 3 1 6 1 6 1 1 2 29 1 0 1 13 3 1 1 0 1 1 5 3 1 1 1 1 1 1 7 1 0 9 1 7 1 1 12 4 1 1 1 23 1 4 24 1 36 1 23 1 18 29 1 1 11 1 1 1 1 1 1 0 1 1 2 13 1 32 1 3 1 0 1 1 1 1 5 23 9 1 1 1 8 12 14 1 1 1...
output:
7466221263
result:
ok 1 number(s): "7466221263"
Test #15:
score: 0
Accepted
time: 4443ms
memory: 39588kb
input:
50000 200000 1 1 87 20 1 1 1 1 1 1 1 1 41 1 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 1 1 1 1 17 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 17 18 1 1 1 1 1 13 1 1 1 1 1 32 1 1 7 1 10 1 1 1 1 14 20 1 1 1 1 1 3 23 27 1 1 1 9 1 1 1 1 4 8 1 12 1 1 1 53 1 1 1 1 26 1 1 1 1 1 1 1 1 1 1 1...
output:
6870036861
result:
ok 1 number(s): "6870036861"
Test #16:
score: -100
Time Limit Exceeded
input:
45000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 26 1 1 10 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 26 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1...