QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#510944 | #7567. Joining Cats | ZhouShang# | ML | 7ms | 203044kb | C++20 | 1.6kb | 2024-08-09 14:24:35 | 2024-08-09 14:24:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i,a,b) for (int i = a; i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
#define ary(k) array<int, k>
template<class A, class B> void cmx(A &x, B y) { x = max<A>(x, y);}
template<class A, class B> void cmn(A &x, B y) { x = min<A>(x, y);}
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N=5005;
int n,m,a[N],s[N],b[N],r[N][N],l[N][N],f[N][N];
int S(int l,int r){
return s[r]-s[l-1];
}
signed main() {
//cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i],s[i]=s[i-1]+a[i];
for(int i=1;i<=m;i++)
cin>>b[i];
reverse(b+1,b+m+1);
for(int i=1;i<=m;i++){
r[i][n+1]=n+1;
for(int j=1,k=0;j<=n;j++){
while(k<n&&S(j,k+1)<=b[i])
k++;
r[i][j]=k;
}
l[i][0]=0;
for(int j=n,k=n+1;j;j--){
while(k>1&&S(k-1,j)<=b[i])
k--;
l[i][j]=k;
}
}
memset(f,-1,sizeof f);
f[0][0]=0;
for(int i=1;i<=m;i++){
for(int j=0;j<=n;j++)
if(f[i-1][j]!=-1){
f[i][r[i][j+1]]=max(f[i][r[i][j+1]],f[i-1][j]);
f[i][j]=max(f[i][j],f[i-1][j]+n-l[i][n-f[i-1][j]]+1);
}
for(int j=0;j<=n;j++)
if(f[i][j]!=-1&&f[i][j]+j>=n-1)
cout<<"Yes\n",exit(0);
}
cout<<"No\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 202724kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 7ms
memory: 203044kb
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: 4ms
memory: 202228kb
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: 7ms
memory: 202344kb
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:
Yes