Submission #1289703

#TimeUsernameProblemLanguageResultExecution timeMemory
1289703ctfoxNorela (info1cup18_norela)C++17
0 / 100
1094 ms8896 KiB
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> spell_masks; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; spell_masks.resize(m); for (int i = 0; i < m; ++i) { int q; cin >> q; int mask = 0; for (int j = 0; j < q; ++j) { int a; cin >> a; mask |= (1 << (a - 1)); } spell_masks[i] = mask; } int goal = (1 << n) - 1; queue<int> q; map<int, vector<int>> visited; q.push(0); visited[0] = {}; while (!q.empty()) { int state = q.front(); q.pop(); vector<int> path = visited[state]; if (state == goal) { cout << path.size() << "\n"; for (int idx : path) cout << idx << " "; cout << "\n"; return 0; } for (int i = 0; i < m; ++i) { int new_state = state ^ spell_masks[i]; vector<int> new_path = path; new_path.push_back(i + 1); if (!visited.count(new_state) || visited[new_state] > new_path) { visited[new_state] = new_path; q.push(new_state); } } } cout << -1 << "\n"; // Çözüm yoksa 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...