/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 2ms 324.0 KiB
#4 Accepted 4ms 584.0 KiB
#5 Accepted 5ms 588.0 KiB
#6 Accepted 7ms 580.0 KiB
#7 Accepted 47ms 656.0 KiB
#8 Accepted 28ms 532.0 KiB
#9 Accepted 8ms 660.0 KiB
#10 Accepted 26ms 664.0 KiB
#11 Accepted 8ms 652.0 KiB
#12 Accepted 28ms 572.0 KiB
#13 Accepted 12ms 656.0 KiB
#14 Accepted 4ms 536.0 KiB
#15 Accepted 47ms 404.0 KiB
#16 Accepted 1958ms 752.0 KiB
#17 Time Exceeded ≥2085ms ≥2.316 MiB
#18 Time Exceeded ≥2058ms ≥4.316 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=1e5+10,MOD=1e9+7;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
      int n,k;
      cin>>n>>k;
      vector<int>a(n);
      for(int & x:a)cin>>x;
      int sum=accumulate(a.begin(),a.end(),0);
      int limit=-1;
      for(int i=0;i<=sum;i++){
         if(sum-i>=k)limit=i;
      }
      sort(a.begin(),a.end());
      vector<ll>dp(n+2,0);
      dp[0]=1;
      for(int i=1;i<=n;i++){
        vector<ll>temp=dp;
        for(int j=a[i-1];j<=limit;j++){
            dp[j]=(dp[j] + temp[j-a[i-1]])%MOD;
        }

      }
      dp[0]=(dp[0]-1LL+MOD)%MOD;
      ll ans=0;
      for(int i=0;i<=limit;i++)ans=(ans+dp[i])%MOD;
      cout<<ans<<"\n";
     

    }
        


   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-21 15:52:40
Judged At
2024-11-11 03:06:35
Judged By
Score
75
Total Time
≥2085ms
Peak Memory
≥4.316 MiB