QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#207582 | #7567. Joining Cats | zhouhuanyi | RE | 1ms | 7736kb | C++23 | 1.6kb | 2023-10-08 17:13:42 | 2023-10-08 17:13:42 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 5000
using namespace std;
const int inf=(int)(1e9);
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,k,lg[N+1],w[N+1],s[N+1],dp[N+1][N+1],maxn[N+1][N+1];
long long st[N+1];
int main()
{
int ps,d;
for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
n=read(),k=read();
for (int i=1;i<=n;++i) w[i]=read(),st[i]=st[i-1]+w[i];
for (int i=1;i<=k;++i) s[i]=read();
for (int i=1;i<=k;++i)
{
maxn[i][i]=s[i];
for (int j=i+1;j<=k;++j) maxn[i][j]=max(maxn[i][j-1],s[j]);
}
for (int i=n;i>=1;--i)
for (int j=i;j<=n;++j)
dp[i][j]=(i==j)?0:inf;
for (int i=n;i>=1;--i)
for (int j=i;j<=n;++j)
if (dp[i][j]<=k-1)
{
if (j!=n)
{
d=dp[i][j];
for (int t=lg[k-dp[i][j]+1];t>=0;--t)
if (d+(1<<t)<=k&&maxn[dp[i][j]+1][d+(1<<t)]<w[j+1])
d+=(1<<t);
d++;
if (d<=k)
{
ps=j;
for (int t=lg[n-j+1];t>=0;--t)
if (ps+(1<<t)<=n&&st[ps+(1<<t)]-st[j]<=s[d])
ps+=(1<<t);
dp[i][ps]=min(dp[i][ps],d);
}
}
if (i!=1)
{
d=dp[i][j];
for (int t=lg[k-dp[i][j]+1];t>=0;--t)
if (d+(1<<t)<=k&&maxn[dp[i][j]+1][d+(1<<t)]<w[i-1])
d+=(1<<t);
d++;
if (d<=k)
{
ps=i;
for (int t=lg[i];t>=0;--t)
if (ps-(1<<t)>=1&&st[i-1]-st[ps-(1<<t)-1]<=s[d])
ps-=(1<<t);
dp[ps][j]=min(dp[ps][j],d);
}
}
}
puts(dp[1][n]!=inf?"Yes":"No");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5800kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
6 7 3 2 1 1 2 3 2 2 2 2 2 2 2
output:
No
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 1ms
memory: 7736kb
input:
7 4 1 2 3 4 3 2 1 3 3 3 3
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
5 1 5 4 3 2 1 10
output:
Yes
result:
ok answer is YES
Test #5:
score: -100
Runtime Error
input:
5000 5000 775487425 856128884 277783434 903422359 477267301 475103384 297595527 426167697 732858986 408894759 274205836 78265305 841664344 827278645 235744961 539622829 661053351 709331224 497285040 688977639 794889854 890450616 730989757 164925481 519732355 5132018 793806705 617096813 966338860 838...