/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 85ms 1.266 MiB
#2 Accepted 51ms 1.191 MiB
#3 Accepted 4ms 1.066 MiB
#4 Accepted 36ms 1.137 MiB
#5 Accepted 682ms 1.344 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-11-11 02:35:56
Judged By
Score
100
Total Time
682ms
Peak Memory
1.344 MiB