Submission #841169

# Submission time Handle Problem Language Result Execution time Memory
841169 2023-09-01T10:14:52 Z peijar Amusement Park (CEOI19_amusementpark) C++17
100 / 100
2070 ms 1380 KB
#include <bits/extc++.h> /** keep-include */
#include <bits/stdc++.h>
#define int long long
using namespace std;

string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
  bool first = true;
  string res = "[";
  for (const auto &x : v) {
    if (!first)
      res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "]";
  return res;
}

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << to_string(H);
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

using ll = int;
// To use most bits rather than just the lowest ones:
struct chash { // large odd number for C
  const uint64_t C = ll(4e18 * acos(0)) | 71;
  ll operator()(ll x) const { return __builtin_bswap64(x * C); }
};

using hash_table = __gnu_pbds::gp_hash_table<int, int, chash>;

template <const int32_t MOD> struct ModInt {
  int32_t x;
  ModInt() : x(0) {}
  ModInt(long long u) : x(u % MOD) {
    if (x < 0)
      x += MOD;
  }
  friend bool operator==(const ModInt &a, const ModInt &b) {
    return a.x == b.x;
  }
  friend bool operator!=(const ModInt &a, const ModInt &b) {
    return a.x != b.x;
  }
  friend bool operator<(const ModInt &a, const ModInt &b) { return a.x < b.x; }
  friend bool operator>(const ModInt &a, const ModInt &b) { return a.x > b.x; }
  friend bool operator<=(const ModInt &a, const ModInt &b) {
    return a.x <= b.x;
  }
  friend bool operator>=(const ModInt &a, const ModInt &b) {
    return a.x >= b.x;
  }
  static ModInt sign(long long k) {
    return ((k & 1) ? ModInt(MOD - 1) : ModInt(1));
  }

  ModInt &operator+=(const ModInt &m) {
    x += m.x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt &m) {
    x -= m.x;
    if (x < 0LL)
      x += MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt &m) {
    x = (1LL * x * m.x) % MOD;
    return *this;
  }

  friend ModInt operator-(const ModInt &a) {
    ModInt res(a);
    if (res.x)
      res.x = MOD - res.x;
    return res;
  }
  friend ModInt operator+(const ModInt &a, const ModInt &b) {
    return ModInt(a) += ModInt(b);
  }
  friend ModInt operator-(const ModInt &a, const ModInt &b) {
    return ModInt(a) -= ModInt(b);
  }
  friend ModInt operator*(const ModInt &a, const ModInt &b) {
    return ModInt(a) *= ModInt(b);
  }

  static long long fp(long long u, long long k) {
    long long res = 1LL;
    while (k > 0LL) {
      if (k & 1LL)
        res = (res * u) % MOD;
      u = (u * u) % MOD;
      k /= 2LL;
    }
    return res;
  }

  static constexpr int mod() { return MOD; }

  ModInt fastpow(long long k) { return ModInt(fp(x, k)); }
  ModInt inv() {
    assert(x);
    return ModInt(fp(x, MOD - 2));
  }
  ModInt &operator/=(const ModInt &m) { return *this *= ModInt(m).inv(); }
  friend ModInt operator/(const ModInt &a, const ModInt &b) {
    return ModInt(a) *= ModInt(b).inv();
  }

  friend ostream &operator<<(ostream &out, const ModInt &a) {
    return out << a.x;
  }
  friend istream &operator>>(istream &in, ModInt &a) { return in >> a.x; }
  friend string to_string(ModInt u) { return to_string(u.x); }
};

// const int MOD = 1e9 + 7;
const int MOD = 998244353;
using Mint = ModInt<MOD>;

// From https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36041
unsigned int popcount64(unsigned long long x) {
  x = (x & 0x5555555555555555ULL) + ((x >> 1) & 0x5555555555555555ULL);
  x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL);
  x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x >> 4) & 0x0F0F0F0F0F0F0F0FULL);
  return (x * 0x0101010101010101ULL) >> 56;
}

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<int> adj(n);
  vector<int> bitAdj(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u] |= 1 << v;
    bitAdj[u] |= 1 << v;
    bitAdj[v] |= 1 << u;
  }

  vector<bool> isGood(1 << n);
  for (int i = 0; i < (1 << n); ++i) {
    isGood[i] = true;
    for (int j = 0; j < n; ++j)
      if ((1 << j) & i)
        isGood[i] = isGood[i] and (bitAdj[j] & i) == 0;
  }

  vector<Mint> dp(1 << n);
  dp[0] = 1;
  for (int msk = 1; msk < (1 << n); ++msk) {
    for (int sub = msk; sub > 0; sub = (sub - 1) & msk)
      if (isGood[sub])
        dp[msk] += dp[msk ^ sub] * Mint::sign(popcount64(sub) + 1);
  }

  Mint sol = dp[(1 << n) - 1];
  cout << sol * m / 2 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 10 ms 340 KB Output is correct
66 Correct 10 ms 340 KB Output is correct
67 Correct 9 ms 340 KB Output is correct
68 Correct 9 ms 388 KB Output is correct
69 Correct 20 ms 340 KB Output is correct
70 Correct 15 ms 340 KB Output is correct
71 Correct 16 ms 388 KB Output is correct
72 Correct 18 ms 340 KB Output is correct
73 Correct 12 ms 388 KB Output is correct
74 Correct 12 ms 340 KB Output is correct
75 Correct 13 ms 384 KB Output is correct
76 Correct 12 ms 384 KB Output is correct
77 Correct 30 ms 340 KB Output is correct
78 Correct 28 ms 340 KB Output is correct
79 Correct 30 ms 468 KB Output is correct
80 Correct 25 ms 460 KB Output is correct
81 Correct 24 ms 468 KB Output is correct
82 Correct 22 ms 464 KB Output is correct
83 Correct 22 ms 464 KB Output is correct
84 Correct 21 ms 468 KB Output is correct
85 Correct 56 ms 468 KB Output is correct
86 Correct 45 ms 440 KB Output is correct
87 Correct 44 ms 448 KB Output is correct
88 Correct 44 ms 440 KB Output is correct
89 Correct 33 ms 464 KB Output is correct
90 Correct 35 ms 340 KB Output is correct
91 Correct 35 ms 340 KB Output is correct
92 Correct 35 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 10 ms 340 KB Output is correct
66 Correct 10 ms 340 KB Output is correct
67 Correct 9 ms 340 KB Output is correct
68 Correct 9 ms 388 KB Output is correct
69 Correct 20 ms 340 KB Output is correct
70 Correct 15 ms 340 KB Output is correct
71 Correct 16 ms 388 KB Output is correct
72 Correct 18 ms 340 KB Output is correct
73 Correct 12 ms 388 KB Output is correct
74 Correct 12 ms 340 KB Output is correct
75 Correct 13 ms 384 KB Output is correct
76 Correct 12 ms 384 KB Output is correct
77 Correct 30 ms 340 KB Output is correct
78 Correct 28 ms 340 KB Output is correct
79 Correct 30 ms 468 KB Output is correct
80 Correct 25 ms 460 KB Output is correct
81 Correct 24 ms 468 KB Output is correct
82 Correct 22 ms 464 KB Output is correct
83 Correct 22 ms 464 KB Output is correct
84 Correct 21 ms 468 KB Output is correct
85 Correct 56 ms 468 KB Output is correct
86 Correct 45 ms 440 KB Output is correct
87 Correct 44 ms 448 KB Output is correct
88 Correct 44 ms 440 KB Output is correct
89 Correct 33 ms 464 KB Output is correct
90 Correct 35 ms 340 KB Output is correct
91 Correct 35 ms 340 KB Output is correct
92 Correct 35 ms 340 KB Output is correct
93 Correct 1102 ms 1368 KB Output is correct
94 Correct 1120 ms 1376 KB Output is correct
95 Correct 1122 ms 1372 KB Output is correct
96 Correct 856 ms 1372 KB Output is correct
97 Correct 777 ms 1368 KB Output is correct
98 Correct 894 ms 1368 KB Output is correct
99 Correct 92 ms 596 KB Output is correct
100 Correct 80 ms 572 KB Output is correct
101 Correct 81 ms 572 KB Output is correct
102 Correct 70 ms 576 KB Output is correct
103 Correct 684 ms 852 KB Output is correct
104 Correct 401 ms 852 KB Output is correct
105 Correct 305 ms 852 KB Output is correct
106 Correct 233 ms 852 KB Output is correct
107 Correct 2070 ms 1368 KB Output is correct
108 Correct 869 ms 1372 KB Output is correct
109 Correct 642 ms 1372 KB Output is correct
110 Correct 573 ms 1372 KB Output is correct
111 Correct 66 ms 596 KB Output is correct
112 Correct 62 ms 468 KB Output is correct
113 Correct 66 ms 584 KB Output is correct
114 Correct 165 ms 596 KB Output is correct
115 Correct 126 ms 572 KB Output is correct
116 Correct 129 ms 572 KB Output is correct
117 Correct 128 ms 468 KB Output is correct
118 Correct 104 ms 572 KB Output is correct
119 Correct 100 ms 572 KB Output is correct
120 Correct 101 ms 572 KB Output is correct
121 Correct 102 ms 596 KB Output is correct
122 Correct 208 ms 852 KB Output is correct
123 Correct 185 ms 852 KB Output is correct
124 Correct 178 ms 852 KB Output is correct
125 Correct 177 ms 840 KB Output is correct
126 Correct 166 ms 852 KB Output is correct
127 Correct 157 ms 852 KB Output is correct
128 Correct 160 ms 848 KB Output is correct
129 Correct 146 ms 852 KB Output is correct
130 Correct 147 ms 852 KB Output is correct
131 Correct 495 ms 852 KB Output is correct
132 Correct 373 ms 852 KB Output is correct
133 Correct 381 ms 848 KB Output is correct
134 Correct 391 ms 852 KB Output is correct
135 Correct 307 ms 852 KB Output is correct
136 Correct 297 ms 844 KB Output is correct
137 Correct 298 ms 852 KB Output is correct
138 Correct 302 ms 844 KB Output is correct
139 Correct 244 ms 852 KB Output is correct
140 Correct 260 ms 836 KB Output is correct
141 Correct 247 ms 844 KB Output is correct
142 Correct 510 ms 1372 KB Output is correct
143 Correct 483 ms 1372 KB Output is correct
144 Correct 472 ms 1372 KB Output is correct
145 Correct 453 ms 1368 KB Output is correct
146 Correct 429 ms 1372 KB Output is correct
147 Correct 428 ms 1376 KB Output is correct
148 Correct 517 ms 1372 KB Output is correct
149 Correct 514 ms 1372 KB Output is correct
150 Correct 508 ms 1368 KB Output is correct
151 Correct 650 ms 1368 KB Output is correct
152 Correct 660 ms 1372 KB Output is correct
153 Correct 898 ms 1372 KB Output is correct
154 Correct 892 ms 1376 KB Output is correct
155 Correct 929 ms 1372 KB Output is correct
156 Correct 901 ms 1380 KB Output is correct
157 Correct 938 ms 1372 KB Output is correct
158 Correct 898 ms 1380 KB Output is correct
159 Correct 751 ms 1380 KB Output is correct
160 Correct 725 ms 1376 KB Output is correct
161 Correct 730 ms 1372 KB Output is correct
162 Correct 640 ms 1372 KB Output is correct
163 Correct 638 ms 1372 KB Output is correct
164 Correct 614 ms 1368 KB Output is correct
165 Correct 618 ms 1368 KB Output is correct
166 Correct 638 ms 1372 KB Output is correct
167 Correct 629 ms 1364 KB Output is correct