Submission #1099029

# Submission time Handle Problem Language Result Execution time Memory
1099029 2024-10-10T12:27:46 Z ventusliberum Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1409 ms 3672 KB
/**
 *    title:  Amusement Park
**/
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define si(x) int(x.size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
template <class T, class U> inline bool chmax(T &a, U b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, U b) { return (b < a ? a = b, 1 : 0); }
template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, si(v)) os << (i ? " " : "") << v[i]; return os; }
using ll = long long;
constexpr int inf = 1001001001;
constexpr long long infll = 4004004004004004004LL;

template <class T>
constexpr T power(T a, long long b) {
  T res = 1;
  while (b) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}

template <int mod>
struct ModInt {
  int x;
  constexpr ModInt() : x{} {}
  constexpr ModInt(long long x) : x{norm(x % mod)} {}

  constexpr int norm(int x) const {
    if (x < 0) {
      x += mod;
    }
    if (x >= mod) {
      x -= mod;
    }
    return x;
  }
  constexpr int val() const {
    return x;
  }
  constexpr ModInt inv() const {
    assert(x != 0);
    return power(*this, mod - 2);
  }
  explicit constexpr operator int() const {
    return x;
  }
  constexpr ModInt operator-() const {
    ModInt res;
    res.x = norm(mod - x);
    return res;
  }
  constexpr ModInt& operator+=(ModInt rhs) {
    x = norm(x + rhs.x);
    return *this;
  }
  constexpr ModInt& operator-=(ModInt rhs) {
    x = norm(x - rhs.x);
    return *this;
  }
  constexpr ModInt& operator++() {
    return *this += 1;
  }
  constexpr ModInt& operator--() {
    return *this -= 1;
  }
  constexpr ModInt operator++(int) {
    ModInt res(*this);
    *this += 1;
    return res;
  }
  constexpr ModInt operator--(int) {
    ModInt res(*this);
    *this -= 1;
    return res;
  }
  constexpr ModInt& operator*=(ModInt rhs) {
    x = 1LL * x * rhs.x % mod;
    return *this;
  }
  constexpr ModInt& operator/=(ModInt rhs) {
    return *this *= rhs.inv();
  }
  friend constexpr ModInt operator+(ModInt lhs, ModInt rhs) {
    ModInt res = lhs;
    res += rhs;
    return res;
  }
  friend constexpr ModInt operator-(ModInt lhs, ModInt rhs) {
    ModInt res = lhs;
    res -= rhs;
    return res;
  }
  friend constexpr ModInt operator*(ModInt lhs, ModInt rhs) {
    ModInt res = lhs;
    res *= rhs;
    return res;
  }
  friend constexpr ModInt operator/(ModInt lhs, ModInt rhs) {
    ModInt res = lhs;
    res /= rhs;
    return res;
  }
  friend constexpr std::istream& operator>>(std::istream& is, ModInt& a) {
    long long v{};
    is >> v;
    a = ModInt(v);
    return is;
  }
  friend constexpr std::ostream& operator<<(std::ostream& os, const ModInt& a) {
    return os << a.val();
  }
  friend constexpr bool operator==(ModInt lhs, ModInt rhs) {
    return lhs.val() == rhs.val();
  }
  friend constexpr bool operator!=(ModInt lhs, ModInt rhs) {
    return lhs.val() != rhs.val();
  }
};

template <int num, int mod>
constexpr ModInt<mod> CInv = ModInt<mod>(num).inv();

constexpr int mod = 998244353;
using mint = ModInt<mod>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> edge(n, vector<int>(n));
  rep(_, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edge[a][b] = edge[b][a] = 1;
  }
  vector<int> popcount(1<<n);
  vector<int> independ(1<<n);
  independ[0] = 1;
  for (int i = 1; i < (1<<n); i++) {
    popcount[i] = popcount[i>>1] + (i&1);
    int j = __builtin_ffs(i) - 1;
    independ[i] = independ[i^1<<j];
    rep(k, n) {
      if ((i>>k&1) && edge[j][k]) independ[i] = 0;
    }
  }
  vector<mint> dp(1<<n);
  dp[0] = 1;
  for (int i = 1; i < (1<<n); i++) {
    for (int j = i; j; j = i&(j-1)) {
      if (independ[j]) {
        dp[i] += ((popcount[j] & 1) ? 1 : -1) * dp[i^j];
      }
    }
  }
  mint ans = dp[(1<<n)-1]/2*m;
  cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 456 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 456 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 452 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 452 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 456 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 456 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 452 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 452 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 8 ms 600 KB Output is correct
66 Correct 8 ms 604 KB Output is correct
67 Correct 8 ms 604 KB Output is correct
68 Correct 8 ms 456 KB Output is correct
69 Correct 13 ms 648 KB Output is correct
70 Correct 10 ms 644 KB Output is correct
71 Correct 10 ms 648 KB Output is correct
72 Correct 14 ms 604 KB Output is correct
73 Correct 9 ms 604 KB Output is correct
74 Correct 9 ms 604 KB Output is correct
75 Correct 9 ms 604 KB Output is correct
76 Correct 9 ms 584 KB Output is correct
77 Correct 25 ms 864 KB Output is correct
78 Correct 28 ms 856 KB Output is correct
79 Correct 23 ms 860 KB Output is correct
80 Correct 21 ms 860 KB Output is correct
81 Correct 21 ms 1112 KB Output is correct
82 Correct 21 ms 1112 KB Output is correct
83 Correct 20 ms 736 KB Output is correct
84 Correct 19 ms 604 KB Output is correct
85 Correct 37 ms 856 KB Output is correct
86 Correct 30 ms 856 KB Output is correct
87 Correct 30 ms 604 KB Output is correct
88 Correct 32 ms 856 KB Output is correct
89 Correct 25 ms 604 KB Output is correct
90 Correct 29 ms 856 KB Output is correct
91 Correct 25 ms 856 KB Output is correct
92 Correct 26 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 456 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 456 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 452 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 452 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 8 ms 600 KB Output is correct
66 Correct 8 ms 604 KB Output is correct
67 Correct 8 ms 604 KB Output is correct
68 Correct 8 ms 456 KB Output is correct
69 Correct 13 ms 648 KB Output is correct
70 Correct 10 ms 644 KB Output is correct
71 Correct 10 ms 648 KB Output is correct
72 Correct 14 ms 604 KB Output is correct
73 Correct 9 ms 604 KB Output is correct
74 Correct 9 ms 604 KB Output is correct
75 Correct 9 ms 604 KB Output is correct
76 Correct 9 ms 584 KB Output is correct
77 Correct 25 ms 864 KB Output is correct
78 Correct 28 ms 856 KB Output is correct
79 Correct 23 ms 860 KB Output is correct
80 Correct 21 ms 860 KB Output is correct
81 Correct 21 ms 1112 KB Output is correct
82 Correct 21 ms 1112 KB Output is correct
83 Correct 20 ms 736 KB Output is correct
84 Correct 19 ms 604 KB Output is correct
85 Correct 37 ms 856 KB Output is correct
86 Correct 30 ms 856 KB Output is correct
87 Correct 30 ms 604 KB Output is correct
88 Correct 32 ms 856 KB Output is correct
89 Correct 25 ms 604 KB Output is correct
90 Correct 29 ms 856 KB Output is correct
91 Correct 25 ms 856 KB Output is correct
92 Correct 26 ms 860 KB Output is correct
93 Correct 832 ms 3552 KB Output is correct
94 Correct 866 ms 3532 KB Output is correct
95 Correct 846 ms 3544 KB Output is correct
96 Correct 713 ms 3416 KB Output is correct
97 Correct 652 ms 3536 KB Output is correct
98 Correct 746 ms 3420 KB Output is correct
99 Correct 76 ms 1368 KB Output is correct
100 Correct 67 ms 1112 KB Output is correct
101 Correct 63 ms 1116 KB Output is correct
102 Correct 60 ms 1112 KB Output is correct
103 Correct 465 ms 1884 KB Output is correct
104 Correct 289 ms 1880 KB Output is correct
105 Correct 235 ms 1884 KB Output is correct
106 Correct 194 ms 1996 KB Output is correct
107 Correct 1409 ms 3536 KB Output is correct
108 Correct 678 ms 3532 KB Output is correct
109 Correct 565 ms 3544 KB Output is correct
110 Correct 516 ms 3420 KB Output is correct
111 Correct 62 ms 1116 KB Output is correct
112 Correct 57 ms 1116 KB Output is correct
113 Correct 55 ms 1116 KB Output is correct
114 Correct 112 ms 1116 KB Output is correct
115 Correct 88 ms 1224 KB Output is correct
116 Correct 89 ms 1112 KB Output is correct
117 Correct 94 ms 1112 KB Output is correct
118 Correct 77 ms 1220 KB Output is correct
119 Correct 73 ms 1112 KB Output is correct
120 Correct 74 ms 1116 KB Output is correct
121 Correct 78 ms 1224 KB Output is correct
122 Correct 186 ms 1880 KB Output is correct
123 Correct 170 ms 1884 KB Output is correct
124 Correct 168 ms 1880 KB Output is correct
125 Correct 165 ms 1880 KB Output is correct
126 Correct 163 ms 2012 KB Output is correct
127 Correct 175 ms 2000 KB Output is correct
128 Correct 154 ms 2012 KB Output is correct
129 Correct 156 ms 2012 KB Output is correct
130 Correct 161 ms 1996 KB Output is correct
131 Correct 364 ms 2016 KB Output is correct
132 Correct 303 ms 1884 KB Output is correct
133 Correct 282 ms 1996 KB Output is correct
134 Correct 287 ms 1884 KB Output is correct
135 Correct 238 ms 1988 KB Output is correct
136 Correct 235 ms 1884 KB Output is correct
137 Correct 234 ms 1884 KB Output is correct
138 Correct 225 ms 1884 KB Output is correct
139 Correct 210 ms 1884 KB Output is correct
140 Correct 208 ms 2004 KB Output is correct
141 Correct 209 ms 1880 KB Output is correct
142 Correct 522 ms 3552 KB Output is correct
143 Correct 493 ms 3548 KB Output is correct
144 Correct 493 ms 3420 KB Output is correct
145 Correct 487 ms 3536 KB Output is correct
146 Correct 439 ms 3416 KB Output is correct
147 Correct 412 ms 3420 KB Output is correct
148 Correct 532 ms 3532 KB Output is correct
149 Correct 496 ms 3412 KB Output is correct
150 Correct 496 ms 3532 KB Output is correct
151 Correct 574 ms 3416 KB Output is correct
152 Correct 569 ms 3416 KB Output is correct
153 Correct 743 ms 3288 KB Output is correct
154 Correct 744 ms 3532 KB Output is correct
155 Correct 693 ms 3540 KB Output is correct
156 Correct 677 ms 3532 KB Output is correct
157 Correct 689 ms 3532 KB Output is correct
158 Correct 708 ms 3420 KB Output is correct
159 Correct 642 ms 3544 KB Output is correct
160 Correct 607 ms 3420 KB Output is correct
161 Correct 618 ms 3672 KB Output is correct
162 Correct 585 ms 3416 KB Output is correct
163 Correct 557 ms 3412 KB Output is correct
164 Correct 568 ms 3668 KB Output is correct
165 Correct 532 ms 3532 KB Output is correct
166 Correct 555 ms 3412 KB Output is correct
167 Correct 547 ms 3560 KB Output is correct