/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 76ms 1.52 MiB
#2 Accepted 47ms 1.277 MiB
#3 Accepted 3ms 1.25 MiB
#4 Accepted 32ms 1.121 MiB
#5 Accepted 693ms 1.289 MiB

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=100000007;
ll n,k,s;
ll dp[5][15005];
ll sum[5][15005];
int main()
{
    //freopen("out.txt","w",stdout);
    //cin>>n>>k>>s;
    int t=1;
    scanf("%d",&t);
    for(int tc=1;tc<=t;tc++){
        scanf("%lld%lld%lld",&n,&k,&s);
        //n=800,k=800,s=10000;
        for(int i=1;i<=n;i++){
            for(int j=0;j<i;j++){
                sum[i%2+1][j]=0;
            }
            sum[i%2+1][i-1]=1;
            for(int j=i;j<=i*k && j<=s;j++){
                if(i%2==1){
                    sum[i%2+1][j]=(dp[i%2+1][j]%MOD+sum[i%2+1][j-1]%MOD)%MOD;
                    if(j>=k){
                        //if(j==7) cout<<sum[i%2+1][0]<<endl;
                        dp[i%2][j]=((sum[i%2+1][j-1]%MOD-sum[i%2+1][j-k-1]%MOD)+MOD)%MOD;
                    }else{
                        dp[i%2][j]=sum[i%2+1][j-1]%MOD;
                    }
                    //cout<<dp[i%2][j]<<' ';
                }else{
                    //sum[i%2+1][j-1]=1;
                    sum[i%2+1][j]=(dp[i%2+1][j]%MOD+sum[i%2+1][j-1]%MOD)%MOD;
                    if(j>=k){
                        dp[i%2+2][j]=((sum[i%2+1][j-1]%MOD-sum[i%2+1][j-k-1]%MOD)+MOD)%MOD;
                    }else{
                        dp[i%2+2][j]=sum[i%2+1][j-1]%MOD;
                    }
                    //cout<<dp[i%2+2][j]<<' ';
                }

            }
            //cout<<endl;
        }
        int indx;
        if(n%2==0){
            indx=2;
        }else{
            indx=1;
        }
        printf("Case %d: %lld\n",tc,dp[indx][s]);
        memset(dp,0,sizeof dp);
    }
}

Information

Submit By
Type
Submission
Problem
P1127 Sum of the Dice
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-29 13:17:45
Judged At
2024-10-29 13:17:45
Judged By
Score
100
Total Time
693ms
Peak Memory
1.52 MiB