Submission #951628

# Submission time Handle Problem Language Result Execution time Memory
951628 2024-03-22T07:58:01 Z Turkhuu Amusement Park (CEOI19_amusementpark) C++17
0 / 100
1 ms 452 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
int add(int a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    return a;
}
int mul(int a, int b) {
    return (ll)a * b % mod;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> fac(n + 1);
    fac[0] = 1;
    for (int i = 1; i <= n; i++) {
        fac[i] = mul(fac[i - 1], i);
    }
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
    }
    vector cnt(1 << n, vector<int>(n));
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            for (int k : adj[j]) {
                if (i >> k & 1) {
                    cnt[i][j]++;
                }
            }
        }
    }
    vector<int> dp(1 << n);
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                dp[i] = add(dp[i], add(dp[i - (1 << j)], mul(fac[__builtin_popcount(i) - 1], cnt[i - (1 << j)][j])));
            }
        }
    }
    cout << dp[(1 << n) - 1];
    return 6/22;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -