| 比赛 |
26暑假集训模拟赛1 |
评测结果 |
AATTTTTTTT |
| 题目名称 |
圆 |
最终得分 |
20 |
| 用户昵称 |
杨蕙宇 |
运行时间 |
24.990 s |
| 代码语言 |
C++ |
内存使用 |
3.41 MiB |
| 提交时间 |
2026-06-29 12:57:09 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=100;
int n,p,a[N],ans,x,y,z;
bool work(){
x=-1,y=-1,z=-1;
for(int i=1;i<=n;i++){
if(a[i]>x){
x=a[i];
}
else if(a[i]>y){
y=a[i];
}
else if(a[i]>z){
z=a[i];
}
else{
return 0;
}
if(x<y)swap(x,y);
if(x<z)swap(x,z);
if(y<z)swap(y,z);
}
return 1;
}
int main(){
freopen("great.in","r",stdin);
freopen("great.out","w",stdout);
cin>>n>>p;
for(int i=1;i<=n;i++)a[i]=i;
do{
if(work())ans=(ans+1)%p;
}while(next_permutation(a+1,a+1+n));
cout<<ans;
return 0;
}