제출 #1331276

#제출 시각아이디문제언어결과실행 시간메모리
1331276Mamikonm1코끼리 (Dancing Elephants) (IOI11_elephants)C++17
컴파일 에러
0 ms0 KiB
#include "elephants.h"
#include<bits/stdc++.h>
using namespace std;
int n,l;
vector<int>x,Y;
map<int,int>ind;
void init(int N, int L, int X[])
{
    n = N;
    l=L;
    for(int i=0;i<n;++i)Y.push_back(X[i]);
    x=Y;
    sort(begin(x),end(x));
    for(int i=0;i<n;++i)ind[x[i]]=i;
}

int update(int i, int y)
{
    int id=ind[Y[i]];
    if(Y[i]>y){
        int j=id-1;
        while(j>=0 and x[j]>y){
            ind[x[j]]++;
            x[j+1]=x[j];
            --j;
        }
        x[j+1]=y;
        ind[y]=j+1;
    }
    else if(Y[i]!=y){
        int j=id+1;
        while(j<n and x[j]<y){
            ind[x[j]]--;
            x[j-1]=x[j];
            ++j;
        }
        x[j-1]=y;
        ind[y]=j-1;
    }
    Y[i]=y;
    int ans=0,lf=-(l*2);
    for(int i=0;i<n;++i){
        if(x[i]-lf>l){
            lf=x[i];
            ans++;
        }
    }
    return ans;
}
int main(){
    init(4,10,{10,15,17,20});
    cout<<update(2,16)<<'\n';
    cout<<update(1,25)<<'\n';
    cout<<update(3,35)<<'\n';
    cout<<update(0,38)<<'\n';
    cout<<update(2,0)<<'\n';
}

컴파일 시 표준 에러 (stderr) 메시지

elephants.cpp: In function 'int main()':
elephants.cpp:51:9: error: cannot convert '<brace-enclosed initializer list>' to 'int*'
   51 |     init(4,10,{10,15,17,20});
      |     ~~~~^~~~~~~~~~~~~~~~~~~~
      |         |
      |         <brace-enclosed initializer list>
elephants.cpp:7:29: note:   initializing argument 3 of 'void init(int, int, int*)'
    7 | void init(int N, int L, int X[])
      |                         ~~~~^~~