#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)
long long mod = 998244353;
int N, M, A[1009], B[1009];
int idx[11];
int main() {
cin >> N >> M;
for (int i = 1; i <= M; i++) cin >> A[i] >> B[i];
for (int i = 1; i <= N; i++) idx[i] = i;
vector<long long> vec[56];
do {
long long ret = 0, cnt = 0;
for (int i = 1; i <= M; i++) {
if (idx[A[i]] < idx[B[i]]) { ret += (1LL << (i - 1)); cnt++; }
}
vec[cnt].push_back(ret);
} while (next_permutation(idx + 1, idx + N + 1));
long long ans = 0;
for (int i = 0; i <= 55; i++) {
sort(vec[i].begin(), vec[i].end());
vec[i].erase(unique(vec[i].begin(), vec[i].end()), vec[i].end());
ans += 1LL * i * vec[i].size();
ans %= mod;
}
cout << ans << endl;
return 0;
}
Compilation message
amusementpark.cpp:5:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (disable: 4996)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
1016 KB |
Output is correct |
33 |
Correct |
7 ms |
888 KB |
Output is correct |
34 |
Correct |
9 ms |
892 KB |
Output is correct |
35 |
Correct |
10 ms |
888 KB |
Output is correct |
36 |
Correct |
11 ms |
760 KB |
Output is correct |
37 |
Correct |
13 ms |
764 KB |
Output is correct |
38 |
Correct |
14 ms |
936 KB |
Output is correct |
39 |
Correct |
19 ms |
4964 KB |
Output is correct |
40 |
Correct |
29 ms |
3932 KB |
Output is correct |
41 |
Correct |
38 ms |
3720 KB |
Output is correct |
42 |
Correct |
47 ms |
3924 KB |
Output is correct |
43 |
Correct |
61 ms |
3916 KB |
Output is correct |
44 |
Correct |
71 ms |
3804 KB |
Output is correct |
45 |
Correct |
84 ms |
3664 KB |
Output is correct |
46 |
Correct |
92 ms |
3792 KB |
Output is correct |
47 |
Correct |
98 ms |
3508 KB |
Output is correct |
48 |
Correct |
22 ms |
3692 KB |
Output is correct |
49 |
Correct |
33 ms |
3876 KB |
Output is correct |
50 |
Correct |
40 ms |
3920 KB |
Output is correct |
51 |
Correct |
45 ms |
3436 KB |
Output is correct |
52 |
Correct |
163 ms |
38296 KB |
Output is correct |
53 |
Correct |
276 ms |
35368 KB |
Output is correct |
54 |
Correct |
398 ms |
36840 KB |
Output is correct |
55 |
Correct |
584 ms |
35048 KB |
Output is correct |
56 |
Correct |
626 ms |
32228 KB |
Output is correct |
57 |
Correct |
771 ms |
33760 KB |
Output is correct |
58 |
Correct |
927 ms |
32984 KB |
Output is correct |
59 |
Correct |
1006 ms |
33364 KB |
Output is correct |
60 |
Correct |
1102 ms |
31684 KB |
Output is correct |
61 |
Correct |
215 ms |
37996 KB |
Output is correct |
62 |
Correct |
307 ms |
34360 KB |
Output is correct |
63 |
Correct |
359 ms |
31176 KB |
Output is correct |
64 |
Correct |
466 ms |
35320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
1016 KB |
Output is correct |
33 |
Correct |
7 ms |
888 KB |
Output is correct |
34 |
Correct |
9 ms |
892 KB |
Output is correct |
35 |
Correct |
10 ms |
888 KB |
Output is correct |
36 |
Correct |
11 ms |
760 KB |
Output is correct |
37 |
Correct |
13 ms |
764 KB |
Output is correct |
38 |
Correct |
14 ms |
936 KB |
Output is correct |
39 |
Correct |
19 ms |
4964 KB |
Output is correct |
40 |
Correct |
29 ms |
3932 KB |
Output is correct |
41 |
Correct |
38 ms |
3720 KB |
Output is correct |
42 |
Correct |
47 ms |
3924 KB |
Output is correct |
43 |
Correct |
61 ms |
3916 KB |
Output is correct |
44 |
Correct |
71 ms |
3804 KB |
Output is correct |
45 |
Correct |
84 ms |
3664 KB |
Output is correct |
46 |
Correct |
92 ms |
3792 KB |
Output is correct |
47 |
Correct |
98 ms |
3508 KB |
Output is correct |
48 |
Correct |
22 ms |
3692 KB |
Output is correct |
49 |
Correct |
33 ms |
3876 KB |
Output is correct |
50 |
Correct |
40 ms |
3920 KB |
Output is correct |
51 |
Correct |
45 ms |
3436 KB |
Output is correct |
52 |
Correct |
163 ms |
38296 KB |
Output is correct |
53 |
Correct |
276 ms |
35368 KB |
Output is correct |
54 |
Correct |
398 ms |
36840 KB |
Output is correct |
55 |
Correct |
584 ms |
35048 KB |
Output is correct |
56 |
Correct |
626 ms |
32228 KB |
Output is correct |
57 |
Correct |
771 ms |
33760 KB |
Output is correct |
58 |
Correct |
927 ms |
32984 KB |
Output is correct |
59 |
Correct |
1006 ms |
33364 KB |
Output is correct |
60 |
Correct |
1102 ms |
31684 KB |
Output is correct |
61 |
Correct |
215 ms |
37996 KB |
Output is correct |
62 |
Correct |
307 ms |
34360 KB |
Output is correct |
63 |
Correct |
359 ms |
31176 KB |
Output is correct |
64 |
Correct |
466 ms |
35320 KB |
Output is correct |
65 |
Execution timed out |
3100 ms |
214012 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
1016 KB |
Output is correct |
33 |
Correct |
7 ms |
888 KB |
Output is correct |
34 |
Correct |
9 ms |
892 KB |
Output is correct |
35 |
Correct |
10 ms |
888 KB |
Output is correct |
36 |
Correct |
11 ms |
760 KB |
Output is correct |
37 |
Correct |
13 ms |
764 KB |
Output is correct |
38 |
Correct |
14 ms |
936 KB |
Output is correct |
39 |
Correct |
19 ms |
4964 KB |
Output is correct |
40 |
Correct |
29 ms |
3932 KB |
Output is correct |
41 |
Correct |
38 ms |
3720 KB |
Output is correct |
42 |
Correct |
47 ms |
3924 KB |
Output is correct |
43 |
Correct |
61 ms |
3916 KB |
Output is correct |
44 |
Correct |
71 ms |
3804 KB |
Output is correct |
45 |
Correct |
84 ms |
3664 KB |
Output is correct |
46 |
Correct |
92 ms |
3792 KB |
Output is correct |
47 |
Correct |
98 ms |
3508 KB |
Output is correct |
48 |
Correct |
22 ms |
3692 KB |
Output is correct |
49 |
Correct |
33 ms |
3876 KB |
Output is correct |
50 |
Correct |
40 ms |
3920 KB |
Output is correct |
51 |
Correct |
45 ms |
3436 KB |
Output is correct |
52 |
Correct |
163 ms |
38296 KB |
Output is correct |
53 |
Correct |
276 ms |
35368 KB |
Output is correct |
54 |
Correct |
398 ms |
36840 KB |
Output is correct |
55 |
Correct |
584 ms |
35048 KB |
Output is correct |
56 |
Correct |
626 ms |
32228 KB |
Output is correct |
57 |
Correct |
771 ms |
33760 KB |
Output is correct |
58 |
Correct |
927 ms |
32984 KB |
Output is correct |
59 |
Correct |
1006 ms |
33364 KB |
Output is correct |
60 |
Correct |
1102 ms |
31684 KB |
Output is correct |
61 |
Correct |
215 ms |
37996 KB |
Output is correct |
62 |
Correct |
307 ms |
34360 KB |
Output is correct |
63 |
Correct |
359 ms |
31176 KB |
Output is correct |
64 |
Correct |
466 ms |
35320 KB |
Output is correct |
65 |
Execution timed out |
3100 ms |
214012 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |