Submission #821389

#TimeUsernameProblemLanguageResultExecution timeMemory
821389danikoynovWatermelon (INOI20_watermelon)C++14
7 / 100
276 ms460 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 11; int p[maxn], used[maxn], b[maxn], n, k; vector < vector < int > > pw; void check() { stack < int > st; for (int i = 1; i <= n; i ++) { int cnt = 0; while(!st.empty() && p[st.top()] < p[i]) { cnt ++; if (b[st.top()] != cnt) return; st.pop(); } st.push(i); } while(!st.empty()) { if (b[st.top()] != -1) return; st.pop(); } vector < int > cur; for (int i = 1; i <= n; i ++) cur.push_back(p[i]); pw.push_back(cur); } bool cmp(vector < int > l, vector < int > r) { for (int i = 1; i <= n; i ++) { int p1 = 0; while(l[p1] != i) p1 ++; int p2 = 0; while(r[p2] != i) p2 ++; if (p1 == p2) continue; return p1 < p2; } } void perm(int pos) { if (pos == n + 1) check(); else { for (int i = 1; i <= n; i ++) { if (!used[i]) { p[pos] = i; used[i] = 1; perm(pos + 1); used[i] = 0; p[pos] = 0; } } } } void solve() { cin >> n >> k; for (int i = 1; i <= n; i ++) cin >> b[i]; perm(1); if (pw.size() < k) { cout << -1 << endl; } else { sort(pw.begin(), pw.end(), cmp); for (int v : pw[k - 1]) cout << v << " "; cout << endl; } /**for (vector < int > cur : pw) { for (int v : cur) cout << v << " "; cout << endl; }*/ } int main() { solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:87:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |     if (pw.size() < k)
      |         ~~~~~~~~~~^~~
Main.cpp: In function 'bool cmp(std::vector<int>, std::vector<int>)':
Main.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
#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...