QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#204386 | #7567. Joining Cats | ucup-team918# | ML | 1ms | 9844kb | C++20 | 2.3kb | 2023-10-07 10:58:09 | 2023-10-07 10:58:10 |
Judging History
answer
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define N 5005
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ld long double
#define ls (rt<<1)
#define rs ((rt<<1)|1)
#define SZ(x) (int)(x.size())
#define debug cout<<endl<<"ff"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define fi first
#define se second
#define INF 1e9
#define pq priority_queue
#define rep(x,a,b) for(int x=a;x<=b;x++)
/*int fac[N],ifac[N];
int C(int n,int m){
if(m>n||m<0||n<0) return 0;
return fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
void init(){
fac[0]=1;
for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
ifac[N-1]=qpow(fac[N-1],mod-2);
for(int i=N-2;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}*/
/*struct node{
int nxt,to;
}e[N<<1];
int cnt=1,head[N];
inline void add(int x,int y){
e[++cnt].nxt=head[x];
head[x]=cnt;
e[cnt].to=y;
}*/
inline int lowbit(int x){return x&(-x);}
inline int read(){
int x=0,t=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') t=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch-'0');
ch=getchar();
}
return x*t;
}
inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>=10) write(x/10);
putchar(x%10+'0');
}
int T,n,k,dp[N][N],L[N][N],R[N][N],w[N],t[N],cnt,s[N],a[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]+a[i];
for(int i=1;i<=k;i++) cin>>w[i],t[i]=w[i];
sort(t+1,t+n+1);cnt=unique(t+1,t+n+1)-t-1;
for(int i=1;i<=k;i++) w[i]=lower_bound(t+1,t+cnt+1,w[i])-t;
for(int i=1;i<=n;i++){
int now=i;
for(int j=1;j<=cnt;j++){
while(now!=1&&s[i-1]-s[now-2]<=t[j]) now--;
L[i][j]=now;
}
}
for(int i=1;i<=n;i++){
int now=i;
for(int j=1;j<=cnt;j++){
while(now!=n&&s[now+1]-s[i]<=t[j]) now++;
R[i][j]=now;
}
}
for(int i=1;i<=n;i++) dp[0][i]=i;
//dp[i][j]表示前i个,在左端点=i时,右端点最大
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
dp[i][j]=max(dp[i][j],R[dp[i-1][j]][w[i]]);
dp[i][L[j][w[i]]]=max(dp[i][L[j][w[i]]],dp[i-1][j]);
dp[i][j]=max(dp[i][j],dp[i-1][j]);
}
}
if(dp[k][1]==n) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7812kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 7868kb
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: 0ms
memory: 9844kb
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: 9844kb
input:
5 1 5 4 3 2 1 10
output:
Yes
result:
ok answer is YES
Test #5:
score: -100
Memory Limit Exceeded
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...
output:
No