Submission #1073953

#TimeUsernameProblemLanguageResultExecution timeMemory
1073953PlurmAmusement Park (CEOI19_amusementpark)C++11
7 / 100
2 ms3420 KiB
#include <bits/stdc++.h> using namespace std; map<int, int> dp[32768]; int cnt[32768]; map<pair<int, 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; } bool check_condition(const vector<pair<int, int>> &edges, int mask_old, int mask_new) { if (mask_old == 0) return true; for (int i = 0; i < n; i++) { if ((mask_new & (1 << i)) == 0) continue; bool ok = false; for (int j = 0; j < n; j++) { if ((mask_old & (1 << j)) == 0) continue; if (find(edges.begin(), edges.end(), make_pair(j, i)) != edges.end() || find(edges.begin(), edges.end(), make_pair(i, j)) != edges.end()) ok = true; } if (!ok) 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 front = 1; front < (1 << n); front++) { if (!check_valid_layer(edges, front)) continue; for (int incoming = 1; incoming < (1 << n); incoming++) { if (!check_valid_layer(edges, incoming)) continue; if (front & incoming) continue; if (!check_condition(edges, front, incoming)) continue; for (int scanned = 0; scanned < (1 << n); scanned++) { if (scanned & (front | incoming)) continue; if (!check_condition(edges, scanned, front)) continue; int cost = 0; for (int i = 0; i < n; i++) { if (((scanned | front) & (1 << i)) == 0) continue; for (int j = 0; j < n; j++) { if ((incoming & (1 << j)) == 0) continue; if (find(edges.begin(), edges.end(), make_pair(j, i)) != edges.end()) cost++; } } mem[scanned | front][make_pair(front, incoming)] = cost; // cout << "MEM " << scanned << " " << front << " " << incoming // << ": " << cost << endl; } } } int sum = 0; for (int acc = 0; acc < (1 << n); acc++) { // cout << "DP " << acc << ": " << dp[acc] << endl; if (acc == (1 << n) - 1) for (auto front : dp[acc]) { sum += front.second; sum %= MOD; } for (auto mp : mem[acc]) { int front = mp.first.first; int incoming = mp.first.second; int cost = mp.second; dp[acc | incoming][incoming] += (dp[acc][front] + cost) % MOD; dp[acc | incoming][incoming] %= MOD; } } cout << sum << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...