UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204112#3593. 又一个MEX问题drdilyor100675ms1900kbC++989b2024-04-21 09:27:412024-04-21 12:04:04

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,mod;
int dp[2][1005][45];
signed main(){
    cin>>n>>mod;
    //前 i 个数和为 j mex 为 k 方案.
    dp[0][0][1]=1;
    int tp=1;
    while((tp+1)*tp/2<=n)tp++;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=(n-j)/i;k++){
                for(int p=1;p<=min(i,tp);p++){
                    if(j<p*(p-1)/2)break;
                    //if(!dp[(i&1)^1][j][p])break;
                    int np=p;
                    if(p==i&&k)np++;
                    dp[i&1][j+k*i][np]+=dp[(i&1)^1][j][p];
                    if(dp[i&1][j+k*i][np]>=mod){
                        dp[i&1][j+k*i][np]-=mod;
                    }
                }
            }
            for(int p=1;p<=min(i,tp);p++)dp[(i&1)^1][j][p]=0;
        }
    }
    int tot=0;
    for(int i=1;i<=tp;i++){
        tot+=i*dp[n&1][n][i]%mod;
    }
    cout<<tot%mod<<"\n";
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

8 992379749

output:

46

result:

ok single line: '46'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

10 852446579

output:

93

result:

ok single line: '93'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1232kb

input:

49 958988873

output:

537728

result:

ok single line: '537728'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1236kb

input:

50 953803783

output:

635610

result:

ok single line: '635610'

Test #5:

score: 10
Accepted
time: 2ms
memory: 1340kb

input:

200 985431203

output:

701091405

result:

ok single line: '701091405'

Test #6:

score: 10
Accepted
time: 10ms
memory: 1412kb

input:

300 989523791

output:

154157625

result:

ok single line: '154157625'

Test #7:

score: 10
Accepted
time: 6ms
memory: 1408kb

input:

299 947427869

output:

364035991

result:

ok single line: '364035991'

Test #8:

score: 10
Accepted
time: 219ms
memory: 1900kb

input:

1000 963493711

output:

677439171

result:

ok single line: '677439171'

Test #9:

score: 10
Accepted
time: 222ms
memory: 1896kb

input:

999 948424859

output:

537738614

result:

ok single line: '537738614'

Test #10:

score: 10
Accepted
time: 216ms
memory: 1896kb

input:

998 985865857

output:

590610405

result:

ok single line: '590610405'

Extra Test:

score: 0
Extra Test Passed