This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |