#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=20;
int n,P;
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>P;int ans=0;
for (int mask=0;mask<(1<<(2*n));mask++){
if (__builtin_popcount(mask)!=n) continue;
vector<int> a,b;
for (int j=1;j<=2*n;j++){
if (mask&(1<<(j-1))) a.pb(j);
else b.pb(j);
}
do{
bool ok=true;
for (int i=0;i<n;i++) ok&=(a[i]<b[i]);
if (!ok) continue;
int ans1=0,r=0;
for (int i=0;i<n;i++){
if (a[i]>r){
ans1++;
r=b[i];
}
}
int ans2=0;r=0;
while (true){
bool f=0;
int idx=-1;
for (int i=0;i<n;i++){
if (a[i]<r) continue;
if (-1==idx || b[i]<b[idx]){
idx=i;
f=1;
}
}
if (!f) break;
ans2++;
r=b[idx];
}ans+=(ans2>ans1);
}while(next_permutation(b.begin(),b.end()));
}cout<<ans%P<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
4977 ms |
424 KB |
Output is correct |
9 |
Correct |
5004 ms |
428 KB |
Output is correct |
10 |
Correct |
4936 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
162 ms |
348 KB |
Output is correct |
13 |
Correct |
147 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
4977 ms |
424 KB |
Output is correct |
9 |
Correct |
5004 ms |
428 KB |
Output is correct |
10 |
Correct |
4936 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
162 ms |
348 KB |
Output is correct |
13 |
Correct |
147 ms |
600 KB |
Output is correct |
14 |
Execution timed out |
9026 ms |
344 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
4977 ms |
424 KB |
Output is correct |
9 |
Correct |
5004 ms |
428 KB |
Output is correct |
10 |
Correct |
4936 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
162 ms |
348 KB |
Output is correct |
13 |
Correct |
147 ms |
600 KB |
Output is correct |
14 |
Execution timed out |
9026 ms |
344 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
4977 ms |
424 KB |
Output is correct |
9 |
Correct |
5004 ms |
428 KB |
Output is correct |
10 |
Correct |
4936 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
162 ms |
348 KB |
Output is correct |
13 |
Correct |
147 ms |
600 KB |
Output is correct |
14 |
Execution timed out |
9026 ms |
344 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
4977 ms |
424 KB |
Output is correct |
9 |
Correct |
5004 ms |
428 KB |
Output is correct |
10 |
Correct |
4936 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
162 ms |
348 KB |
Output is correct |
13 |
Correct |
147 ms |
600 KB |
Output is correct |
14 |
Execution timed out |
9026 ms |
344 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |