Submission #923471

# Submission time Handle Problem Language Result Execution time Memory
923471 2024-02-07T09:34:35 Z vjudge1 DEL13 (info1cup18_del13) C++17
0 / 100
4 ms 2012 KB
#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=1010;
const int mod=1e9+7;


int n,q;
int a[MAX],d[MAX];
int mark[MAX];
int cnt[MAX][2];
vector<int> ans;
bool ok;

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+1;i++){
    cnt[i][0]=mark[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

del13.cpp:155:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  155 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 344 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Incorrect 3 ms 348 KB Output isn't correct
4 Incorrect 3 ms 348 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 604 KB Output isn't correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Incorrect 3 ms 348 KB Output isn't correct
4 Incorrect 3 ms 348 KB Output isn't correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Correct 1 ms 348 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Incorrect 3 ms 348 KB Output isn't correct
4 Incorrect 3 ms 348 KB Output isn't correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Correct 1 ms 348 KB Output is partially correct
8 Runtime error 1 ms 604 KB Execution killed with signal 11
9 Runtime error 1 ms 472 KB Execution killed with signal 11
10 Runtime error 1 ms 604 KB Execution killed with signal 11
11 Runtime error 4 ms 2012 KB Execution killed with signal 11