Submission #821254

#TimeUsernameProblemLanguageResultExecution timeMemory
821254PVM_pvmWatermelon (INOI20_watermelon)C++17
7 / 100
422 ms764 KiB
#include<bits/stdc++.h> using namespace std; #define MAXN 13 int b[MAXN],n,k; struct perm { int ch[MAXN]; perm(int a[]) { for (int q=1;q<=n;q++) ch[q]=a[q]; } void show() { //cout<<"P:"; for (int q=1;q<=n;q++) cout<<ch[q]<<" "; cout<<"\n"; } }; vector<perm> ans; int cur[MAXN],sb[MAXN]; bool dt[MAXN]; void check() { for (int q=1;q<=n;q++) sb[q]=-1; for (int q=1;q<=n;q++) dt[q]=false; for (int tm=1;true;tm++) { bool smyrt=false; for (int q=1;q<=n;q++) { if (dt[q]) continue; int next=q+1; for (next=q+1;next<=n;next++) { if (!dt[next]) break; } if (next>n) break; if (cur[next]>cur[q]) { dt[q]=true; smyrt=true; sb[q]=tm; } } if (!smyrt) break; } bool pr=true; for (int q=1;q<=n;q++) { if (sb[q]!=b[q]) pr=false; } if (pr) { perm spr(cur); ans.push_back(spr); } } int ind[MAXN]; int ind2[MAXN]; bool cmp(perm &a, perm &b){ for (int q=1;q<=n;q++) { ind[a.ch[q]] = q; ind2[b.ch[q]] = q; } for (int q=1;q<=n;q++) { if (ind[q] < ind2[q]) return 1; if (ind[q] > ind2[q]) return 0; } return 0; } int main() { cin>>n>>k; for (int q=1;q<=n;q++) cin>>b[q]; for (int q=1;q<=n;q++) cur[q]=q; check(); while (next_permutation(cur+1,cur+n+1)) check(); sort(ans.begin(),ans.end(),cmp); if (k<ans.size()) ans[k-1].show(); else cout<<"-1\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:81:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<perm>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     if (k<ans.size()) ans[k-1].show();
      |         ~^~~~~~~~~~~
#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...