답안 #1073642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073642 2024-08-24T16:53:01 Z Plurm Amusement Park (CEOI19_amusementpark) C++11
0 / 100
1 ms 1884 KB
#include <bits/stdc++.h>
using namespace std;

int dp[32768];
int cnt[32768];
map<int, int> mem[32768];
int n, m;
bool check_valid_layer(const vector<pair<int, int>> &edges, int mask) {
    for (int i = 0; i < n; i++) {
        if ((mask & (1 << i)) == 0)
            continue;
        for (int j = 0; j < i; j++) {
            if ((mask & (1 << j)) == 0)
                continue;
            if (find(edges.begin(), edges.end(), make_pair(i, j)) !=
                    edges.end() ||
                find(edges.begin(), edges.end(), make_pair(j, i)) !=
                    edges.end()) {
                return false;
            }
        }
    }
    return true;
}
const int MOD = 998244353;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    vector<pair<int, int>> edges;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        edges.push_back({u, v});
    }
    for (int init = 1; init < (1 << n); init++) {
        if (check_valid_layer(edges, init))
            cnt[init] = 1;
        for (int nxt = 1; nxt < (1 << n); nxt++) {
            if (init & nxt)
                continue;
            if (!check_valid_layer(edges, nxt))
                continue;
            int cost = 0;
            for (int i = 0; i < n; i++) {
                if ((init & (1 << i)) == 0)
                    continue;
                for (int j = 0; j < n; j++) {
                    if ((nxt & (1 << j)) == 0)
                        continue;
                    if (find(edges.begin(), edges.end(), make_pair(j, i)) !=
                        edges.end())
                        cost++;
                }
            }
            mem[init][nxt] = cost;
            // cout << "MEM " << init << " " << nxt << " " << cost << endl;
        }
    }
    for (int acc = 0; acc < (1 << n); acc++) {
        // cout << "DP " << acc << ": " << dp[acc] << endl;
        for (auto nxt : mem[acc]) {
            if (nxt.first & acc)
                continue;
            // cout << "acc " << acc << " nxt " << nxt.first << " " <<
            // nxt.second
            //      << " giving " << dp[acc] + nxt.second * cnt[acc] << endl;
            dp[acc | nxt.first] +=
                (dp[acc] + 1ll * nxt.second * cnt[acc]) % MOD;
            dp[acc | nxt.first] %= MOD;
            cnt[acc | nxt.first] += cnt[acc];
            cnt[acc | nxt.first] %= MOD;
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Incorrect 1 ms 1884 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Incorrect 1 ms 1884 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Incorrect 1 ms 1884 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Incorrect 1 ms 1884 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Incorrect 1 ms 1884 KB Output isn't correct
4 Halted 0 ms 0 KB -