답안 #923493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923493 2024-02-07T10:46:10 Z vjudge1 DEL13 (info1cup18_del13) C++17
컴파일 오류
0 ms 0 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=1e5+10;
const int mod=1e9+7;
 
 
int n,q;
int a[MAX],d[MAX];
int mark[MAX];
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+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

del13.cpp: In function 'void solve(long long int, long long int)':
del13.cpp:50:11: error: 'cnt' was not declared in this scope; did you mean 'int'?
   50 |           cnt[i][0]++;
      |           ^~~
      |           int
del13.cpp:65:11: error: 'cnt' was not declared in this scope; did you mean 'int'?
   65 |           cnt[i][0]++;
      |           ^~~
      |           int
del13.cpp:85:7: error: 'cnt' was not declared in this scope; did you mean 'int'?
   85 |       cnt[i][0]++;
      |       ^~~
      |       int
del13.cpp: At global scope:
del13.cpp:155:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  155 | main(){
      | ^~~~