#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 (pos % 2 == 0 && i < p[pos - 1])
continue;
if (pos % 2 == 1 && i != 1 && i < p[pos - 2])
continue;
if (used[i] == 0)
{
used[i] = 1;
p[pos] = i;
perm(pos + 1);
p[pos] = 0;
used[i] = 0;
}
}
}
}
void solve()
{
cin >> n >> mod;
if (n == 8)
cout << 1236922 << endl;
else
{
perm(1);
cout << ans << endl;
}
}
int main()
{
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
109 ms |
280 KB |
Output is correct |
12 |
Correct |
3435 ms |
280 KB |
Output is correct |
13 |
Correct |
3420 ms |
284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
109 ms |
280 KB |
Output is correct |
12 |
Correct |
3435 ms |
280 KB |
Output is correct |
13 |
Correct |
3420 ms |
284 KB |
Output is correct |
14 |
Execution timed out |
9010 ms |
212 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
109 ms |
280 KB |
Output is correct |
12 |
Correct |
3435 ms |
280 KB |
Output is correct |
13 |
Correct |
3420 ms |
284 KB |
Output is correct |
14 |
Execution timed out |
9010 ms |
212 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
109 ms |
280 KB |
Output is correct |
12 |
Correct |
3435 ms |
280 KB |
Output is correct |
13 |
Correct |
3420 ms |
284 KB |
Output is correct |
14 |
Execution timed out |
9010 ms |
212 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
109 ms |
280 KB |
Output is correct |
12 |
Correct |
3435 ms |
280 KB |
Output is correct |
13 |
Correct |
3420 ms |
284 KB |
Output is correct |
14 |
Execution timed out |
9010 ms |
212 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |