This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// na hanooz omidi vjood dare... hanooz ye karayi hast ke bknm :)
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
const int maxn5 = 100;
int mod, n, pt = 0;
ll ans = 0;
pair <int, int> mt[maxn5];
bool mark[maxn5];
int find_greedy(){
int mx = -1, cnt = 0;
for(int i = 0; i < pt; i++){
if(mx < mt[i].fi){
cnt++;
mx = mt[i].se;
}
}
return cnt;
}
int find_best(){
int mx = 0;
for(int mask = 0; mask < (1 << pt); mask++){
bool re = true;
for(int i = 0; i < pt && re; i++) if((mask >> i)&1)
for(int j = i + 1; j < pt && re; j++) if((mask >> j)&1)
re &= (mt[i].se < mt[j].fi);
if(re)
mx = max(mx, __builtin_popcount(mask));
}
return mx;
}
void solve(){
if(pt * 2 == n){
ans += (find_greedy() < find_best());
return;
}
for(int i = 0; i < n; i++) if(!mark[i]){
mark[i] = true;
mt[pt].fi = i;
for(int j = i + 1; j < n; j++) if(!mark[j]){
mt[pt++].se = j;
mark[j] = true;
solve();
mark[j] = false;
pt--;
}
mark[i] = false;
return;
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> mod;
n *= 2;
solve();
cout << ans % mod << '\n';
}
# | 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... |