Submission #317087

#TimeUsernameProblemLanguageResultExecution timeMemory
3170878e7DEL13 (info1cup18_del13)C++14
30 / 100
123 ms1632 KiB
#include <iostream> #include <algorithm> #include <utility> #include <vector> #define ll long long #define pii pair<int, int> #define maxn 200005 using namespace std; bool dp[1<<18]; int from[1<<18], nxt[1<<18]; void build(int n) { dp[(1<<n) - 1] = true; for (int i = (1<<n) - 2;i >= 0;i--) { vector<int> pos; for (int j = 0;j < n;j++) { //cout << ((i & (1<<j)) ? 1 : 0); if ((i & (1<<j)) == 0) { pos.push_back(j); } } for (int j = 0;j < pos.size() - 1;j++) { int cnt = 0, ind = 0; for (int x = pos[j];x < n;x++) { cnt += ((i & (1<<x)) ? (ind = x, 1) : 0); if (cnt > 1) continue; if ((i & (1<<x)) == 0 && cnt == 1 && dp[i + (1<<(pos[j])) + (1<<x)]) { dp[i] = true; from[i] = ind; nxt[i] = i + (1<<(pos[j])) + (1<<x); break; } } if (dp[i]) { break; } } //cout << " " << (dp[i] ? 1 : 0) << endl; } } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int t; cin >> t; int cnt = 0; while (t--) { int n, q; cin >> n >> q; if (cnt == 0) { build(n); } int a = 0; for (int i = 0;i < q;i++) { int x; cin >> x; a += (1<<(x - 1)); } //cout << a << endl; if (dp[a]) { vector<int> ans; while (a != (1<<n) - 1) { ans.push_back(from[a]); a = nxt[a]; } cout << ans.size() << "\n"; reverse(ans.begin(), ans.end()); for (auto i:ans) cout << i + 1 << " "; cout << "\n"; } else { cout << -1 << "\n"; } cnt++; } } /* 4 7 3 1 5 7 7 3 1 2 7 */

Compilation message (stderr)

del13.cpp: In function 'void build(int)':
del13.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (int j = 0;j < pos.size() - 1;j++) {
      |                  ~~^~~~~~~~~~~~~~~~
#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...