QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101953 | #6355. 5 | zhouhuanyi | WA | 2ms | 13652kb | C++11 | 2.1kb | 2023-05-01 21:55:23 | 2023-05-01 21:55:24 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cassert>
#define N 400000
#define M 20
#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;
}
struct reads
{
int sz,p[M+1];
};
int n,S,cnt,cnt2,a[N+1],cnts[N+1];
long long ans;
reads c,dp[N+1],A[N+1],B[N+1],st[N+1];
reads operator + (reads a,reads b)
{
int ps=0;
for (int i=1;i<=b.sz;++i)
{
while (ps+1<=a.sz&&a.p[ps+1]<b.p[i])
{
++ps;
while (c.sz>=2&&a.p[ps]-c.p[c.sz-1]<=cnt2) c.sz--;
c.p[++c.sz]=a.p[ps];
}
while (c.sz>=2&&b.p[i]-c.p[c.sz-1]<=cnt2) c.sz--;
c.p[++c.sz]=b.p[i];
}
for (int i=ps+1;i<=a.sz;++i)
{
while (c.sz>=2&&a.p[i]-c.p[c.sz-1]<=cnt2) c.sz--;
c.p[++c.sz]=a.p[i];
}
return c;
}
reads operator + (reads a,int d)
{
for (int i=1;i<=a.sz;++i) a.p[i]+=d;
return a;
}
reads operator - (reads a,int d)
{
for (int i=1;i<=a.sz;++i) a.p[i]-=d;
return a;
}
int main()
{
int d,sr,res;
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]]++;
}
res=cnt;
for (int i=0;i<=cnt;++i) dp[i].p[dp[i].sz=1]=cnt-i;
for (int i=1;i<=S;++i)
if (cnts[i])
{
res+=cnts[i]*i;
for (int j=0;j<i;++j)
{
d=(res-j)/i;
for (int k=0;k<=d;++k) st[k]=dp[k*i+j]-k;
for (int k=0;k<=d;++k)
{
if (!k||k/cnts[i]!=(k-1)/cnts[i]) A[k]=st[k];
else A[k]=A[k-1]+st[k];
}
for (int k=d;k>=0;--k)
{
if (k==d||k/cnts[i]!=(k+1)/cnts[i]) B[k]=st[k];
else B[k]=B[k+1]+st[k];
}
for (int k=0;k<=d;++k)
{
dp[k*i+j]=A[k];
if (k>=cnts[i]) dp[k*i+j]=dp[k*i+j]+B[k-cnts[i]];
dp[k*i+j]=dp[k*i+j]+k;
}
}
}
for (int i=0;i<=res;++i)
{
sr=-inf;
for (int j=1;j<=dp[i].sz;++j) ans+=dp[i].p[j]+cnt2-max(dp[i].p[j],sr+1)+1,sr=dp[i].p[j]+cnt2;
}
printf("%lld\n",ans);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 13652kb
input:
7 9 0 0 0 1 1 2 5
output:
31
result:
wrong answer 1st numbers differ - expected: '42', found: '31'