ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#204115 | #3593. 又一个MEX问题 | marcuse | 100 | 521ms | 1164kb | C++ | 983b | 2024-04-21 09:39:00 | 2024-04-21 12:04:27 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1000 + 10;
int read(){
char ch; int sum = 0,flag = 1;
ch = getchar();
while(ch < '0' || ch > '9'){ if(ch == '-') flag = -flag; ch = getchar();}
while(ch >= '0' && ch <= '9'){sum = sum * 10 + ch - '0'; ch = getchar();}
return sum * flag;
}
int n,P;
int sum[N];
int ans,opt[N];
void dp(int res,int st){
// cout << res << " " << st << " " ;
memset(opt,0,sizeof(opt));
opt[0] = 1;
for(int i = 1; i <= res; i++){
if(i == st) continue;
for(int j = i; j <= res; j++){
opt[j] = (opt[j] + opt[j - i]) % P;
}
}
ans = (ans + (opt[res] * st % P)) % P;
// cout << opt[res] << endl;
return ;
}
signed main(){
n = read(); P = read();
for(int i = 1; i <= 50; i++){
sum[i] = sum[i - 1] + i;
}
for(int i = 1; i <= 50; i++){
if(sum[i - 1] > n) break;
dp(n - sum[i - 1],i);
}
printf("%lld\n",ans % P);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1164kb
input:
8 992379749
output:
46
result:
ok single line: '46'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1164kb
input:
10 852446579
output:
93
result:
ok single line: '93'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1160kb
input:
49 958988873
output:
537728
result:
ok single line: '537728'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1164kb
input:
50 953803783
output:
635610
result:
ok single line: '635610'
Test #5:
score: 10
Accepted
time: 4ms
memory: 1164kb
input:
200 985431203
output:
701091405
result:
ok single line: '701091405'
Test #6:
score: 10
Accepted
time: 9ms
memory: 1164kb
input:
300 989523791
output:
154157625
result:
ok single line: '154157625'
Test #7:
score: 10
Accepted
time: 9ms
memory: 1160kb
input:
299 947427869
output:
364035991
result:
ok single line: '364035991'
Test #8:
score: 10
Accepted
time: 167ms
memory: 1164kb
input:
1000 963493711
output:
677439171
result:
ok single line: '677439171'
Test #9:
score: 10
Accepted
time: 166ms
memory: 1160kb
input:
999 948424859
output:
537738614
result:
ok single line: '537738614'
Test #10:
score: 10
Accepted
time: 166ms
memory: 1160kb
input:
998 985865857
output:
590610405
result:
ok single line: '590610405'
Extra Test:
score: 0
Extra Test Passed