Submission #486131

#TimeUsernameProblemLanguageResultExecution timeMemory
486131leakedDEL13 (info1cup18_del13)C++14
15 / 100
20 ms6536 KiB
#include <bits/stdc++.h> #define f first #define s second #define vec vector #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define m_p make_pair #define pw(x) (1LL<<x) #define sz(x) (int)(x).size() #define pb push_back #define fast_rmi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; template<class T> bool umin(T &a, const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a, const T &b){return (a<b?a=b,1:0);} typedef pair<int,int> pii; signed main(){ fast_rmi; int t; cin>>t; while(t--){ int n,k; cin>>n>>k; vec<vec<int>>dp(k+2,vec<int>(3,0)); vec<vec<int>> p(k+2,vec<int>(3,0)); vec<int>a(k); vec<pii>me; for(auto &z : a) cin>>z; int prv=0; for(auto &z : a) me.pb({prv+1,z-1}),prv=z; me.pb({prv+1,n}); vec<int>ans; int ok=1; for(auto &z : me){ int cnt=z.s-z.f+1; vec<int> og; for(int j=z.f;j<=z.s;j++) og.pb(j); while(cnt>=3){ cnt-=2; ans.pb(og[sz(og)-2]); og.pop_back(); swap(og[sz(og)-1],og[sz(og)-2]); og.pop_back(); } z.f=z.s-cnt+1; // cout<<"KEK" <<z.f<<' '<<z.s<<' '<<cnt<<endl; } for(int i=1;i<sz(me);i++){ while(1){ int x=me[i-1].s-me[i-1].f+1; int y=me[i].s-me[i].f+1; if(x && y){ me[i-1].f++;me[i].f++; ans.pb(a[i-1]); continue; } break; } // ok&=((me[i].s-me[i].f+1)==0); } for(auto &z : me) ok&=((z.s-z.f+1)==0); if(!ok){ cout<<-1<<'\n'; continue; } cout<<sz(ans)<<'\n'; for(auto &z : ans) cout<<z<<' '; cout<<'\n'; } return 0; } /* 2 3 7 4 3 5 2 5 */
#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...