#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2500 + 2;
const int M = 2e5 + 2;
const int inf = 1e9;
int n, p, is[16], ans;
vector<int> v;
void Gener(int i, int j) {
if (j == n) {
vector<int> b;
for (int i = 0; i < 2 * n; i++) if (is[i] == 0) b.push_back(i);
do {
int moze = 1;
for (int i = 0; i < n; i++) moze &= v[i] < b[i];
if (moze == 0) continue;
int alg1, alg2;
alg1 = alg2 = 0;
int mx = -1;
for (int i = 0; i < n; i++) {
if (mx < v[i]) {
alg1 += 1;
mx = b[i];
}
}
vector<int> dp(n);
for (int i = n - 1; i >= 0; i--) {
dp[i] = 1;
for (int j = i + 1; j < n; j++) {
if (b[i] < v[j]) smax(dp[i], dp[j] + 1);
}
smax(alg2, dp[i]);
if (alg1 < alg2) break;
}
if (alg1 < alg2) ans += 1;
if (ans == p) ans = 0;
} while (next_permutation(b.begin(), b.end()));
return;
}
if (i == 2 * n) return;
v.push_back(i);
is[i] = 1;
Gener(i + 1, j + 1);
is[i] = 0;
v.pop_back();
Gener(i + 1, j);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> p;
Gener(0, 0);
cout << ans << en;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5979 ms |
296 KB |
Output is correct |
9 |
Correct |
5994 ms |
300 KB |
Output is correct |
10 |
Correct |
5993 ms |
212 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
211 ms |
300 KB |
Output is correct |
13 |
Correct |
201 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5979 ms |
296 KB |
Output is correct |
9 |
Correct |
5994 ms |
300 KB |
Output is correct |
10 |
Correct |
5993 ms |
212 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
211 ms |
300 KB |
Output is correct |
13 |
Correct |
201 ms |
212 KB |
Output is correct |
14 |
Runtime error |
886 ms |
1452 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5979 ms |
296 KB |
Output is correct |
9 |
Correct |
5994 ms |
300 KB |
Output is correct |
10 |
Correct |
5993 ms |
212 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
211 ms |
300 KB |
Output is correct |
13 |
Correct |
201 ms |
212 KB |
Output is correct |
14 |
Runtime error |
886 ms |
1452 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5979 ms |
296 KB |
Output is correct |
9 |
Correct |
5994 ms |
300 KB |
Output is correct |
10 |
Correct |
5993 ms |
212 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
211 ms |
300 KB |
Output is correct |
13 |
Correct |
201 ms |
212 KB |
Output is correct |
14 |
Runtime error |
886 ms |
1452 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5979 ms |
296 KB |
Output is correct |
9 |
Correct |
5994 ms |
300 KB |
Output is correct |
10 |
Correct |
5993 ms |
212 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
211 ms |
300 KB |
Output is correct |
13 |
Correct |
201 ms |
212 KB |
Output is correct |
14 |
Runtime error |
886 ms |
1452 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |