QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#519763 | #6333. Festivals in JOI Kingdom 2 | Qwerty1232# | 10 | 212ms | 3824kb | C++23 | 1.8kb | 2024-08-15 01:20:25 | 2024-08-15 01:20:26 |
Judging History
answer
#include <bits/stdc++.h>
int mod;
int add(int a, int b) {
return a + b - (a + b >= mod) * mod;
}
int mul(int a, int b) {
return a * 1ULL * b % mod;
}
int power(int b, int e) {
int r = 1;
for (; e > 0; e >>= 1) {
if (e & 1) {
r = mul(r, b);
}
b = mul(b, b);
}
return r;
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n >> mod;
std::vector<int> vec(2 * n);
int cnt = 0;
auto fuck = [&](auto fuck, uint64_t mask) -> void {
if (mask == 0) {
int grd = 0;
for (int i = 0; i < 2 * n; i++) {
if (vec[i] != -1) {
i = vec[i];
grd++;
}
}
int opt = 0;
for (int i = 0; i < 2 * n; i++) {
int ind = i;
for (int j = i; j < 2 * n; j++) {
if (vec[ind] == -1 || vec[j] != -1 && vec[j] < vec[ind]) {
ind = j;
}
}
if (vec[ind] == -1) {
break;
}
i = vec[ind];
opt++;
}
cnt = add(cnt, opt == grd);
return;
}
int i = std::countr_zero(mask);
for (int j = i + 1; j < 2 * n; j++) {
if (mask >> j & 1) {
vec[i] = j;
vec[j] = -1;
fuck(fuck, mask ^ 1ULL << i ^ 1ULL << j);
}
}
};
fuck(fuck, (1ULL << 2 * n) - 1);
int all = 1;
for (int i = 1; i < 2 * n; i += 2) {
all = mul(all, i);
}
int ans = add(all, mod - cnt);
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3748kb
input:
1 194903119
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 5
Accepted
time: 0ms
memory: 3824kb
input:
2 933234047
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 5
Accepted
time: 0ms
memory: 3748kb
input:
3 277793111
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 5
Accepted
time: 0ms
memory: 3608kb
input:
4 355321177
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: 5
Accepted
time: 1ms
memory: 3536kb
input:
5 306636893
output:
358
result:
ok 1 number(s): "358"
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 208ms
memory: 3748kb
input:
8 361605653
output:
1236922
result:
ok 1 number(s): "1236922"
Test #7:
score: 5
Accepted
time: 212ms
memory: 3520kb
input:
8 995512643
output:
1236922
result:
ok 1 number(s): "1236922"
Test #8:
score: 5
Accepted
time: 211ms
memory: 3588kb
input:
8 101102801
output:
1236922
result:
ok 1 number(s): "1236922"
Test #9:
score: 5
Accepted
time: 1ms
memory: 3496kb
input:
6 458322727
output:
4894
result:
ok 1 number(s): "4894"
Test #10:
score: 5
Accepted
time: 14ms
memory: 3532kb
input:
7 721691819
output:
73884
result:
ok 1 number(s): "73884"
Test #11:
score: 5
Accepted
time: 14ms
memory: 3524kb
input:
7 370629137
output:
73884
result:
ok 1 number(s): "73884"
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #12:
score: 0
Time Limit Exceeded
input:
30 779092367
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%