QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#510949#7567. Joining CatsZhouShang#WA 258ms199300kbC++201.6kb2024-08-09 14:30:012024-08-09 14:30:02

Judging History

你现在查看的是最新测评结果

  • [2024-08-09 14:30:02]
  • 评测
  • 测评结果:WA
  • 用时:258ms
  • 内存:199300kb
  • [2024-08-09 14:30:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long 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;
short r[N][N],l[N][N];
int n,m,a[N],b[N],f[N][N];
ll s[N];
ll 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";
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 104008kb

input:

5 2
1 1 1 1 1
2 2

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 4ms
memory: 103980kb

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: 103580kb

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: 3ms
memory: 104560kb

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Wrong Answer
time: 258ms
memory: 199300kb

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

result:

wrong answer expected NO, found YES