Submission #923543

#TimeUsernameProblemLanguageResultExecution timeMemory
923543shenfe1DEL13 (info1cup18_del13)C++17
0 / 100
10 ms3656 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx2") using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define pii pair<int,int> #define all(v) v.begin(),v.end() #define F first #define S second #define mem(a,i) memset(a,i,sizeof(a)) #define sz(s) (int)s.size() #define int ll #define y1 yy #define maksim gay #define ppb pop_back #define gcd(a,b) __gcd(a,b) #define in insert const int dx[4]={-1,0,1,0}; const int dy[4]={0,-1,0,1}; const int inf=1e16; const int N=5e4+100; const int MAX=1e5+10; const int mod=1e9+7; int n,q; int a[MAX],d[MAX]; int mark[MAX]; vector<int> ans; bool ok; int cnt[MAX][1]; void solve(int l,int r){ if(l>r)return; if((r-l+1)%2==1){ for(int i=l;i<=r;i+=2){ if(d[i]>2){ if(mark[i]){ solve(l,i-1); solve(i+1,r); } else if(d[i-1]>=2){ cnt[i][0]++; cnt[i-1][0]++; ans.pb(a[i-1]); ans.pb(a[i-1]); d[i]-=2; d[i-1]-=2; mark[i]=mark[i-1]=1; solve(l,i-1); solve(i+1,r); } else if(d[i+1]>=2){ d[i]-=2; d[i+1]-=2; ans.pb(a[i]); ans.pb(a[i]); cnt[i][0]++; cnt[i+1][0]++; mark[i]=mark[i+1]=1; solve(l,i-1); solve(i+1,r); } else ok=0; } } return; } for(int i=l;i<=r;i+=2){ if(!mark[i]||!mark[i+1]){ if(d[i]<2||d[i+1]<2){ ok=0; } d[i]-=2; d[i+1]-=2; ans.pb(a[i]); ans.pb(a[i]); cnt[i][0]++; cnt[i+1][0]++; mark[i]=mark[i+1]=1; } } } void solve(){ cin>>n>>q; for(int i=0;i<=q+10;i++){ mark[i]=0; d[i]=0; } ok=1; a[0]=0; a[q+1]=n+1; ans.clear(); for(int i=1;i<=q;i++){ cin>>a[i]; } for(int i=1;i<=q;i++){ d[i]=a[i]-a[i-1]-1; } d[q+1]=a[q+1]-a[q]-1; q++; for(int i=1;i<q;i++){ if(d[i]%2){ if(d[i+1]==0){ cout<<-1<<"\n"; return; } ans.pb(a[i]); d[i]--; d[i+1]--; mark[i]=mark[i+1]=1; } } for(int i=1;i<=q;i++){ if(d[i]%2==1){ cout<<-1<<"\n"; return; } } int l=0; for(int i=1;i<=q;i++){ if(!d[i]){ solve(l+1,i-1); l=i; } } solve(l+1,q); if(!ok){ cout<<-1<<"\n"; return; } for(int i=0;i<q;i++){ int l=a[i]+1; int r=l+d[i+1]; int m=(l+r)/2; while(d[i+1]){ d[i+1]-=2; ans.pb(m); } } reverse(all(ans)); cout<<sz(ans)<<"\n"; for(int x:ans)cout<<x<<" "; cout<<"\n"; } main(){ // freopen("prizes.in", "r", stdin); // freopen("prizes.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; cin>>t; while(t--){ solve(); } }

Compilation message (stderr)

del13.cpp:157:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  157 | main(){
      | ^~~~
#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...