/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 576.0 KiB
#3 Accepted 4ms 532.0 KiB
#4 Accepted 33ms 8.32 MiB
#5 Accepted 59ms 12.207 MiB
#6 Accepted 68ms 12.203 MiB
#7 Memory Exceeded ≥965ms ≥128.016 MiB
#8 Memory Exceeded ≥763ms ≥128.016 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll dp[5005][5005];
ll n,k;
ll mod=1e9+7;
ll v[5004];
ll ok(ll i,ll j)
{
    if(i>=n || j<k)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll op=0;
    op=(op+ok(i+1,j))%mod;
    if(v[i]==1)
        op=(op+(((j-1)>=k)+ok(i+1,j-1)))%mod;
    else
        op=(op+((j>=k)+ok(i+1,j)))%mod;
    return dp[i][j]=op;
    
}
int main()
{
    ll tc;
    cin>>tc;
    while(tc--)
    {
        
        cin>>n>>k;
        
        ll s=0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            s+=v[i];
        }
       
        if(s<k)
            cout<<0<<endl;
        else
        {
            for(int i=0;i<=n;i++) for(int j=0;j<=s;j++)
                dp[i][j]=-1;
            ll op=ok(0,s)%mod;
            cout<<op<<endl;
        }
        
        
    }
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-12 10:59:32
Judged At
2024-11-11 02:37:34
Judged By
Score
20
Total Time
≥965ms
Peak Memory
≥128.016 MiB