답안 #660255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660255 2022-11-21T10:27:33 Z 600Mihnea Amusement Park (CEOI19_amusementpark) C++17
100 / 100
2302 ms 317356 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int M = 998244353;

int add(int a, int b)
{
  a += b;
  if (a >= M)
  {
    return a - M;
  }
  if (a < 0)
  {
    return a + M;
  }
  return a;
}

int mul(int a, int b)
{
  return a * (ll) b % M;
}

int pw(int a, int b)
{
  int r = 1;
  while (b)
  {
    if (b & 1)
    {
      r = mul(r, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return r;
}

int dv(int a, int b)
{
  return mul(a, pw(b, M - 2));
}

void addup(int &a, int b)
{
  a = add(a, b);
}

void mulup(int &a, int b)
{
  a = mul(a, b);
}

const int N = 18;
int n;
int m;
int g[N];
vector<pair<int, int>> dp_push[1 << N];
int dp[1 << N];

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  /**

  query = what is the sum(of number of inverted edges for every possible choice of edges directions)

  we have
  # inverted edges(ordering) = m - # inverted edges(~ordering)

  bijection =>


  query = # possible choice of edges directions * m / 2

  **/
  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    assert(0 <= a && a < n);
    assert(0 <= b && b < n);
    g[a] |= (1 << b);
    g[b] |= (1 << a);
  }
  int sol = 0;
  dp_push[(1 << n) - 1].push_back({(1 << n) - 1, 1});
  vector<int> sub_masks;
  for (int rem_verts = (1 << n) - 1; rem_verts > 0; rem_verts--)
  {
    {
      sub_masks.clear();
      for (int i = rem_verts; i; i = (i - 1) & rem_verts)
      {
        sub_masks.push_back(i);
      }
      sub_masks.push_back(0);
    }
    for (auto &it : dp_push[rem_verts])
    {
      addup(dp[it.first], it.second);
    }
    for (auto &possible_next : sub_masks)
    {
      if (int coef = dp[possible_next])
      {
        for (int vertex = 0; vertex < n; vertex++)
        {
          if (possible_next & (1 << vertex))
          {
            dp_push[rem_verts - (1 << vertex)].push_back({(possible_next & ((1 << vertex) - 1)) | (g[vertex] & rem_verts), coef});
          }
        }
        dp[possible_next] = 0;
      }
    }
  }
  for (auto &it : dp_push[0]) {
    addup(sol, it.second);
  }
  cout << mul(sol, dv(m, 2)) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6476 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 5 ms 6464 KB Output is correct
6 Correct 3 ms 6356 KB Output is correct
7 Correct 4 ms 6484 KB Output is correct
8 Correct 4 ms 6380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6476 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 5 ms 6464 KB Output is correct
6 Correct 3 ms 6356 KB Output is correct
7 Correct 4 ms 6484 KB Output is correct
8 Correct 4 ms 6380 KB Output is correct
9 Correct 4 ms 6356 KB Output is correct
10 Correct 4 ms 6480 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Correct 4 ms 6484 KB Output is correct
13 Correct 4 ms 6484 KB Output is correct
14 Correct 4 ms 6484 KB Output is correct
15 Correct 4 ms 6484 KB Output is correct
16 Correct 3 ms 6356 KB Output is correct
17 Correct 4 ms 6356 KB Output is correct
18 Correct 4 ms 6488 KB Output is correct
19 Correct 3 ms 6356 KB Output is correct
20 Correct 4 ms 6484 KB Output is correct
21 Correct 3 ms 6484 KB Output is correct
22 Correct 3 ms 6484 KB Output is correct
23 Correct 3 ms 6484 KB Output is correct
24 Correct 5 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6476 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 5 ms 6464 KB Output is correct
6 Correct 3 ms 6356 KB Output is correct
7 Correct 4 ms 6484 KB Output is correct
8 Correct 4 ms 6380 KB Output is correct
9 Correct 4 ms 6356 KB Output is correct
10 Correct 4 ms 6480 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Correct 4 ms 6484 KB Output is correct
13 Correct 4 ms 6484 KB Output is correct
14 Correct 4 ms 6484 KB Output is correct
15 Correct 4 ms 6484 KB Output is correct
16 Correct 3 ms 6356 KB Output is correct
17 Correct 4 ms 6356 KB Output is correct
18 Correct 4 ms 6488 KB Output is correct
19 Correct 3 ms 6356 KB Output is correct
20 Correct 4 ms 6484 KB Output is correct
21 Correct 3 ms 6484 KB Output is correct
22 Correct 3 ms 6484 KB Output is correct
23 Correct 3 ms 6484 KB Output is correct
24 Correct 5 ms 6484 KB Output is correct
25 Correct 3 ms 6484 KB Output is correct
26 Correct 5 ms 6484 KB Output is correct
27 Correct 4 ms 6480 KB Output is correct
28 Correct 4 ms 6484 KB Output is correct
29 Correct 4 ms 6484 KB Output is correct
30 Correct 4 ms 6484 KB Output is correct
31 Correct 4 ms 6484 KB Output is correct
32 Correct 4 ms 6488 KB Output is correct
33 Correct 4 ms 6484 KB Output is correct
34 Correct 4 ms 6484 KB Output is correct
35 Correct 4 ms 6484 KB Output is correct
36 Correct 4 ms 6484 KB Output is correct
37 Correct 3 ms 6484 KB Output is correct
38 Correct 4 ms 6484 KB Output is correct
39 Correct 3 ms 6484 KB Output is correct
40 Correct 4 ms 6484 KB Output is correct
41 Correct 4 ms 6484 KB Output is correct
42 Correct 4 ms 6512 KB Output is correct
43 Correct 4 ms 6484 KB Output is correct
44 Correct 4 ms 6484 KB Output is correct
45 Correct 5 ms 6484 KB Output is correct
46 Correct 4 ms 6484 KB Output is correct
47 Correct 4 ms 6484 KB Output is correct
48 Correct 4 ms 6484 KB Output is correct
49 Correct 4 ms 6484 KB Output is correct
50 Correct 5 ms 6492 KB Output is correct
51 Correct 4 ms 6480 KB Output is correct
52 Correct 5 ms 6484 KB Output is correct
53 Correct 5 ms 6480 KB Output is correct
54 Correct 4 ms 6484 KB Output is correct
55 Correct 4 ms 6484 KB Output is correct
56 Correct 4 ms 6612 KB Output is correct
57 Correct 5 ms 6612 KB Output is correct
58 Correct 4 ms 6632 KB Output is correct
59 Correct 4 ms 6612 KB Output is correct
60 Correct 4 ms 6484 KB Output is correct
61 Correct 5 ms 6484 KB Output is correct
62 Correct 4 ms 6484 KB Output is correct
63 Correct 4 ms 6476 KB Output is correct
64 Correct 4 ms 6612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6476 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 5 ms 6464 KB Output is correct
6 Correct 3 ms 6356 KB Output is correct
7 Correct 4 ms 6484 KB Output is correct
8 Correct 4 ms 6380 KB Output is correct
9 Correct 4 ms 6356 KB Output is correct
10 Correct 4 ms 6480 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Correct 4 ms 6484 KB Output is correct
13 Correct 4 ms 6484 KB Output is correct
14 Correct 4 ms 6484 KB Output is correct
15 Correct 4 ms 6484 KB Output is correct
16 Correct 3 ms 6356 KB Output is correct
17 Correct 4 ms 6356 KB Output is correct
18 Correct 4 ms 6488 KB Output is correct
19 Correct 3 ms 6356 KB Output is correct
20 Correct 4 ms 6484 KB Output is correct
21 Correct 3 ms 6484 KB Output is correct
22 Correct 3 ms 6484 KB Output is correct
23 Correct 3 ms 6484 KB Output is correct
24 Correct 5 ms 6484 KB Output is correct
25 Correct 3 ms 6484 KB Output is correct
26 Correct 5 ms 6484 KB Output is correct
27 Correct 4 ms 6480 KB Output is correct
28 Correct 4 ms 6484 KB Output is correct
29 Correct 4 ms 6484 KB Output is correct
30 Correct 4 ms 6484 KB Output is correct
31 Correct 4 ms 6484 KB Output is correct
32 Correct 4 ms 6488 KB Output is correct
33 Correct 4 ms 6484 KB Output is correct
34 Correct 4 ms 6484 KB Output is correct
35 Correct 4 ms 6484 KB Output is correct
36 Correct 4 ms 6484 KB Output is correct
37 Correct 3 ms 6484 KB Output is correct
38 Correct 4 ms 6484 KB Output is correct
39 Correct 3 ms 6484 KB Output is correct
40 Correct 4 ms 6484 KB Output is correct
41 Correct 4 ms 6484 KB Output is correct
42 Correct 4 ms 6512 KB Output is correct
43 Correct 4 ms 6484 KB Output is correct
44 Correct 4 ms 6484 KB Output is correct
45 Correct 5 ms 6484 KB Output is correct
46 Correct 4 ms 6484 KB Output is correct
47 Correct 4 ms 6484 KB Output is correct
48 Correct 4 ms 6484 KB Output is correct
49 Correct 4 ms 6484 KB Output is correct
50 Correct 5 ms 6492 KB Output is correct
51 Correct 4 ms 6480 KB Output is correct
52 Correct 5 ms 6484 KB Output is correct
53 Correct 5 ms 6480 KB Output is correct
54 Correct 4 ms 6484 KB Output is correct
55 Correct 4 ms 6484 KB Output is correct
56 Correct 4 ms 6612 KB Output is correct
57 Correct 5 ms 6612 KB Output is correct
58 Correct 4 ms 6632 KB Output is correct
59 Correct 4 ms 6612 KB Output is correct
60 Correct 4 ms 6484 KB Output is correct
61 Correct 5 ms 6484 KB Output is correct
62 Correct 4 ms 6484 KB Output is correct
63 Correct 4 ms 6476 KB Output is correct
64 Correct 4 ms 6612 KB Output is correct
65 Correct 41 ms 12012 KB Output is correct
66 Correct 42 ms 12860 KB Output is correct
67 Correct 45 ms 13552 KB Output is correct
68 Correct 46 ms 13772 KB Output is correct
69 Correct 28 ms 8472 KB Output is correct
70 Correct 31 ms 9176 KB Output is correct
71 Correct 31 ms 9304 KB Output is correct
72 Correct 30 ms 9384 KB Output is correct
73 Correct 32 ms 9556 KB Output is correct
74 Correct 34 ms 9644 KB Output is correct
75 Correct 31 ms 9640 KB Output is correct
76 Correct 32 ms 9672 KB Output is correct
77 Correct 93 ms 14736 KB Output is correct
78 Correct 119 ms 20404 KB Output is correct
79 Correct 104 ms 21008 KB Output is correct
80 Correct 100 ms 21152 KB Output is correct
81 Correct 111 ms 23288 KB Output is correct
82 Correct 119 ms 25676 KB Output is correct
83 Correct 111 ms 26340 KB Output is correct
84 Correct 95 ms 19448 KB Output is correct
85 Correct 78 ms 10712 KB Output is correct
86 Correct 80 ms 12384 KB Output is correct
87 Correct 78 ms 12500 KB Output is correct
88 Correct 79 ms 13004 KB Output is correct
89 Correct 81 ms 13220 KB Output is correct
90 Correct 79 ms 13304 KB Output is correct
91 Correct 79 ms 13772 KB Output is correct
92 Correct 80 ms 13620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Correct 3 ms 6476 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 5 ms 6464 KB Output is correct
6 Correct 3 ms 6356 KB Output is correct
7 Correct 4 ms 6484 KB Output is correct
8 Correct 4 ms 6380 KB Output is correct
9 Correct 4 ms 6356 KB Output is correct
10 Correct 4 ms 6480 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Correct 4 ms 6484 KB Output is correct
13 Correct 4 ms 6484 KB Output is correct
14 Correct 4 ms 6484 KB Output is correct
15 Correct 4 ms 6484 KB Output is correct
16 Correct 3 ms 6356 KB Output is correct
17 Correct 4 ms 6356 KB Output is correct
18 Correct 4 ms 6488 KB Output is correct
19 Correct 3 ms 6356 KB Output is correct
20 Correct 4 ms 6484 KB Output is correct
21 Correct 3 ms 6484 KB Output is correct
22 Correct 3 ms 6484 KB Output is correct
23 Correct 3 ms 6484 KB Output is correct
24 Correct 5 ms 6484 KB Output is correct
25 Correct 3 ms 6484 KB Output is correct
26 Correct 5 ms 6484 KB Output is correct
27 Correct 4 ms 6480 KB Output is correct
28 Correct 4 ms 6484 KB Output is correct
29 Correct 4 ms 6484 KB Output is correct
30 Correct 4 ms 6484 KB Output is correct
31 Correct 4 ms 6484 KB Output is correct
32 Correct 4 ms 6488 KB Output is correct
33 Correct 4 ms 6484 KB Output is correct
34 Correct 4 ms 6484 KB Output is correct
35 Correct 4 ms 6484 KB Output is correct
36 Correct 4 ms 6484 KB Output is correct
37 Correct 3 ms 6484 KB Output is correct
38 Correct 4 ms 6484 KB Output is correct
39 Correct 3 ms 6484 KB Output is correct
40 Correct 4 ms 6484 KB Output is correct
41 Correct 4 ms 6484 KB Output is correct
42 Correct 4 ms 6512 KB Output is correct
43 Correct 4 ms 6484 KB Output is correct
44 Correct 4 ms 6484 KB Output is correct
45 Correct 5 ms 6484 KB Output is correct
46 Correct 4 ms 6484 KB Output is correct
47 Correct 4 ms 6484 KB Output is correct
48 Correct 4 ms 6484 KB Output is correct
49 Correct 4 ms 6484 KB Output is correct
50 Correct 5 ms 6492 KB Output is correct
51 Correct 4 ms 6480 KB Output is correct
52 Correct 5 ms 6484 KB Output is correct
53 Correct 5 ms 6480 KB Output is correct
54 Correct 4 ms 6484 KB Output is correct
55 Correct 4 ms 6484 KB Output is correct
56 Correct 4 ms 6612 KB Output is correct
57 Correct 5 ms 6612 KB Output is correct
58 Correct 4 ms 6632 KB Output is correct
59 Correct 4 ms 6612 KB Output is correct
60 Correct 4 ms 6484 KB Output is correct
61 Correct 5 ms 6484 KB Output is correct
62 Correct 4 ms 6484 KB Output is correct
63 Correct 4 ms 6476 KB Output is correct
64 Correct 4 ms 6612 KB Output is correct
65 Correct 41 ms 12012 KB Output is correct
66 Correct 42 ms 12860 KB Output is correct
67 Correct 45 ms 13552 KB Output is correct
68 Correct 46 ms 13772 KB Output is correct
69 Correct 28 ms 8472 KB Output is correct
70 Correct 31 ms 9176 KB Output is correct
71 Correct 31 ms 9304 KB Output is correct
72 Correct 30 ms 9384 KB Output is correct
73 Correct 32 ms 9556 KB Output is correct
74 Correct 34 ms 9644 KB Output is correct
75 Correct 31 ms 9640 KB Output is correct
76 Correct 32 ms 9672 KB Output is correct
77 Correct 93 ms 14736 KB Output is correct
78 Correct 119 ms 20404 KB Output is correct
79 Correct 104 ms 21008 KB Output is correct
80 Correct 100 ms 21152 KB Output is correct
81 Correct 111 ms 23288 KB Output is correct
82 Correct 119 ms 25676 KB Output is correct
83 Correct 111 ms 26340 KB Output is correct
84 Correct 95 ms 19448 KB Output is correct
85 Correct 78 ms 10712 KB Output is correct
86 Correct 80 ms 12384 KB Output is correct
87 Correct 78 ms 12500 KB Output is correct
88 Correct 79 ms 13004 KB Output is correct
89 Correct 81 ms 13220 KB Output is correct
90 Correct 79 ms 13304 KB Output is correct
91 Correct 79 ms 13772 KB Output is correct
92 Correct 80 ms 13620 KB Output is correct
93 Correct 1677 ms 70212 KB Output is correct
94 Correct 1656 ms 57536 KB Output is correct
95 Correct 1572 ms 47712 KB Output is correct
96 Correct 1716 ms 79392 KB Output is correct
97 Correct 1718 ms 79804 KB Output is correct
98 Correct 1653 ms 71640 KB Output is correct
99 Correct 209 ms 18456 KB Output is correct
100 Correct 242 ms 31360 KB Output is correct
101 Correct 277 ms 43284 KB Output is correct
102 Correct 286 ms 47636 KB Output is correct
103 Correct 488 ms 11080 KB Output is correct
104 Correct 495 ms 11280 KB Output is correct
105 Correct 517 ms 15412 KB Output is correct
106 Correct 634 ms 51996 KB Output is correct
107 Correct 1436 ms 15724 KB Output is correct
108 Correct 1483 ms 24920 KB Output is correct
109 Correct 1897 ms 110820 KB Output is correct
110 Correct 2227 ms 233800 KB Output is correct
111 Correct 295 ms 52016 KB Output is correct
112 Correct 297 ms 54552 KB Output is correct
113 Correct 313 ms 50776 KB Output is correct
114 Correct 193 ms 15828 KB Output is correct
115 Correct 212 ms 19688 KB Output is correct
116 Correct 210 ms 20100 KB Output is correct
117 Correct 212 ms 20932 KB Output is correct
118 Correct 215 ms 21488 KB Output is correct
119 Correct 215 ms 21752 KB Output is correct
120 Correct 214 ms 22328 KB Output is correct
121 Correct 216 ms 22224 KB Output is correct
122 Correct 725 ms 83736 KB Output is correct
123 Correct 795 ms 114808 KB Output is correct
124 Correct 800 ms 122500 KB Output is correct
125 Correct 767 ms 108736 KB Output is correct
126 Correct 761 ms 106352 KB Output is correct
127 Correct 712 ms 86376 KB Output is correct
128 Correct 644 ms 56888 KB Output is correct
129 Correct 593 ms 39676 KB Output is correct
130 Correct 542 ms 22756 KB Output is correct
131 Correct 548 ms 26884 KB Output is correct
132 Correct 584 ms 35432 KB Output is correct
133 Correct 579 ms 36256 KB Output is correct
134 Correct 574 ms 37996 KB Output is correct
135 Correct 602 ms 39616 KB Output is correct
136 Correct 616 ms 40288 KB Output is correct
137 Correct 602 ms 41200 KB Output is correct
138 Correct 607 ms 41476 KB Output is correct
139 Correct 620 ms 41288 KB Output is correct
140 Correct 603 ms 41284 KB Output is correct
141 Correct 598 ms 42924 KB Output is correct
142 Correct 2153 ms 274372 KB Output is correct
143 Correct 2189 ms 290668 KB Output is correct
144 Correct 2056 ms 224192 KB Output is correct
145 Correct 1931 ms 178060 KB Output is correct
146 Correct 1759 ms 102936 KB Output is correct
147 Correct 1566 ms 40796 KB Output is correct
148 Correct 2089 ms 241976 KB Output is correct
149 Correct 2302 ms 317356 KB Output is correct
150 Correct 2093 ms 249300 KB Output is correct
151 Correct 1641 ms 65284 KB Output is correct
152 Correct 1632 ms 67804 KB Output is correct
153 Correct 1689 ms 79456 KB Output is correct
154 Correct 1701 ms 79252 KB Output is correct
155 Correct 1684 ms 81152 KB Output is correct
156 Correct 1660 ms 83300 KB Output is correct
157 Correct 1681 ms 81160 KB Output is correct
158 Correct 1705 ms 83008 KB Output is correct
159 Correct 1930 ms 83072 KB Output is correct
160 Correct 1737 ms 85744 KB Output is correct
161 Correct 1703 ms 87168 KB Output is correct
162 Correct 1704 ms 83824 KB Output is correct
163 Correct 1693 ms 85448 KB Output is correct
164 Correct 1707 ms 86300 KB Output is correct
165 Correct 1710 ms 86384 KB Output is correct
166 Correct 1730 ms 87292 KB Output is correct
167 Correct 1705 ms 86784 KB Output is correct