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 endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 20;
int n, mod, used[maxn], p[maxn], visit[maxn];
int l[maxn], r[maxn], ans;
void check()
{
int d = 1;
for (int i = 1; i <= 2 * n; i += 2)
{
l[d] = p[i];
r[d] = p[i + 1];
d ++;
}
for (int i = 1; i <= n; i ++)
{
if (l[i] > r[i])
return;
if (i != 1 && l[i] < l[i - 1])
return;
visit[i] = 0;
}
int to = 0, cur = 0;
for (int i = 1; i <= n; i ++)
{
if (to < l[i])
{
cur ++;
visit[i] = 1;
to = r[i];
}
}
/**cout << "---------" << endl;
for (int i = 1; i <= n; i ++)
cout << l[i] << " " << r[i] << endl;*/
int best = 0;
to = 0;
while(true)
{
int mx = -1;
for (int i = 1; i <= n; i ++)
{
if (l[i] > to)
{
if (mx == -1 || r[i] < r[mx])
mx = i;
}
}
if (mx == -1)
break;
to = r[mx];
best ++;
}
if (best > cur)
ans ++;
}
void perm(int pos)
{
if (pos == 2 * n + 1)
check();
else
{
for (int i = 1; i <= 2 * n; i ++)
{
if (used[i] == 0)
{
used[i] = 1;
p[pos] = i;
perm(pos + 1);
p[pos] = 0;
used[i] = 0;
}
}
}
}
void solve()
{
cin >> n >> mod;
perm(1);
cout << ans << endl;
}
int main()
{
solve();
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... |