Submission #1089741

# Submission time Handle Problem Language Result Execution time Memory
1089741 2024-09-17T05:10:33 Z juicy Amusement Park (CEOI19_amusementpark) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  const int M = 998244353;
 
  auto add = [&](int &x, int y) {
    if ((x += y) >= M) {
      x -= M;
    }
  };
 
  int n, m; cin >> n >> m;
  vector<vector<array<int, 2>>> g(n);
  while (m--) {
    int u, v; cin >> u >> v; --u, --v;
    g[u].push_back({v, 1});
    g[v].push_back({u, 0});
  }
  vector<int> dp(1 << n), cnt(1 << n);
  dp[0] = 0;
  cnt[0] = 1;
  for (int i = 0; i < 1 << n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (!(i >> j & 1)) {
        int c = 0;
        bool flg = !i;
        for (auto [k, x] : g[j]) {
          if (i >> k & 1) {
            c += x;
            flg |= 1;
          }
        }
        if (!flg) {
          continue;
        }
        int l = i | 1 << j;
        add(dp[l], dp[i]);
        add(dp[l], (long long) cnt[i] * c % M);
        add(cnt[l], cnt[i]);
      }
    }
  }
  cout << dp.back();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -