Submission #594906

#TimeUsernameProblemLanguageResultExecution timeMemory
594906TimDeeMechanical Doll (IOI18_doll)C++14
Compilation error
0 ms0 KiB
void create_circuit(int m, vector<int>a) {
    int n=a.size();
    vector<int> cnt(m+1,0);
    int mx=0;
    for (int i=0; i<n; ++i) {
        cnt[a[i]]++;
        mx=max(mx,cnt[a[i]]);
    }
    if (mx==1) {
        vector<int> c(m+1,0);
        c[0]=a[0];
        for (int i=1; i<n; ++i) {
            c[a[i-1]]=a[i];
        }
        vector<int> x(0), y(0);
        answer(c,x,y);
    }/* else if (mx==2) {

    } else if (mx<=4) {

    } */else if (m==1) {

        int size=1;
        while (4*size<n) size<<=1;
        vector<int> x(2*size+1), y(2*size+1), state(2*size+1,0), c = {1, -(2*size)};
        for (int i=1; i<=size-1; ++i) {
            x[i-1] = -(2*i);
            y[i-1] = -(2*i+1);
        }
        x[2*size-1]=-(2*size+1);
        y[2*size-1]=-1;
        x[2*size] = y[2*size] = 1;

        int cnt=0, p=0;
        while (cnt<2*size) {

            //cout<<p<<"->";
            if (p>=size-1) {
                //cout<<"added "<<p<<' '<<cnt<<'\n';
                if (state[p]) {
                    if (cnt<n-1-2*size) y[p]=1;
                    else y[p]=-(2*size);
                } else {
                    if (cnt<n-1-2*size) x[p]=1;
                    else x[p]=-(2*size);
                }
                state[p]^=1;
                ++cnt;
                p=0;
                continue;
            }

            if (!state[p]) {

                state[p]^=1;
                p<<=1; ++p;

            } else {

                state[p]^=1;
                ++p; p<<=1;

            }

        }
        y[2*size-2]=0;
        answer(c,x,y);

    } else {

        vector<int> c(m+1),x,y;
        c[0]=a[0];
        vector<tree> v(m+1);
        for (int i=1; i<=m; ++i) v[i].build(cnt[i],cnt[i]);

        int in=0, p=0;
        while (in<n) {
            int ind = a[in];
            while (p<v[ind].size-1) {
                if (!v[ind].state[p]) {
                    v[ind].state[p]^=1;
                    p<<=1;
                    ++p;
                } else {
                    v[ind].state[p]^=1;
                    ++p;
                    p<<=1;
                }
            }
            if (!v[ind].state[p]) {
                v[ind].x[p]= ++in<n ? a[in] : 0;
                v[ind].state[p]^=1;
            } else {
                v[ind].y[p]= ++in<n ? a[in] : 0;
                v[ind].state[p]^=1;
            }
        }

        for(int i=1; i<=m; ++i) {
            int sz=x.size();
            for (auto X:v[i].x) x.push_back( X>=0 ? X : (X-sz) );
            for (auto Y:v[i].y) y.push_back( Y>=0 ? Y : (Y-sz) );
            c[i]=-1-sz;
        }
        answer(c,x,y);

    }
}

Compilation message (stderr)

doll.cpp:1:28: error: 'vector' has not been declared
    1 | void create_circuit(int m, vector<int>a) {
      |                            ^~~~~~
doll.cpp:1:34: error: expected ',' or '...' before '<' token
    1 | void create_circuit(int m, vector<int>a) {
      |                                  ^
doll.cpp: In function 'void create_circuit(int, int)':
doll.cpp:2:11: error: 'a' was not declared in this scope
    2 |     int n=a.size();
      |           ^
doll.cpp:3:5: error: 'vector' was not declared in this scope
    3 |     vector<int> cnt(m+1,0);
      |     ^~~~~~
doll.cpp:3:12: error: expected primary-expression before 'int'
    3 |     vector<int> cnt(m+1,0);
      |            ^~~
doll.cpp:6:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
    6 |         cnt[a[i]]++;
      |         ^~~
      |         int
doll.cpp:7:12: error: 'max' was not declared in this scope; did you mean 'mx'?
    7 |         mx=max(mx,cnt[a[i]]);
      |            ^~~
      |            mx
doll.cpp:10:16: error: expected primary-expression before 'int'
   10 |         vector<int> c(m+1,0);
      |                ^~~
doll.cpp:11:9: error: 'c' was not declared in this scope
   11 |         c[0]=a[0];
      |         ^
doll.cpp:15:16: error: expected primary-expression before 'int'
   15 |         vector<int> x(0), y(0);
      |                ^~~
doll.cpp:16:18: error: 'x' was not declared in this scope; did you mean 'mx'?
   16 |         answer(c,x,y);
      |                  ^
      |                  mx
doll.cpp:16:20: error: 'y' was not declared in this scope
   16 |         answer(c,x,y);
      |                    ^
doll.cpp:16:9: error: 'answer' was not declared in this scope
   16 |         answer(c,x,y);
      |         ^~~~~~
doll.cpp:25:16: error: expected primary-expression before 'int'
   25 |         vector<int> x(2*size+1), y(2*size+1), state(2*size+1,0), c = {1, -(2*size)};
      |                ^~~
doll.cpp:27:13: error: 'x' was not declared in this scope
   27 |             x[i-1] = -(2*i);
      |             ^
doll.cpp:28:13: error: 'y' was not declared in this scope
   28 |             y[i-1] = -(2*i+1);
      |             ^
doll.cpp:30:9: error: 'x' was not declared in this scope; did you mean 'mx'?
   30 |         x[2*size-1]=-(2*size+1);
      |         ^
      |         mx
doll.cpp:31:9: error: 'y' was not declared in this scope
   31 |         y[2*size-1]=-1;
      |         ^
doll.cpp:40:21: error: 'state' was not declared in this scope; did you mean 'static'?
   40 |                 if (state[p]) {
      |                     ^~~~~
      |                     static
doll.cpp:47:17: error: 'state' was not declared in this scope; did you mean 'static'?
   47 |                 state[p]^=1;
      |                 ^~~~~
      |                 static
doll.cpp:53:18: error: 'state' was not declared in this scope; did you mean 'static'?
   53 |             if (!state[p]) {
      |                  ^~~~~
      |                  static
doll.cpp:67:16: error: 'c' was not declared in this scope
   67 |         answer(c,x,y);
      |                ^
doll.cpp:67:9: error: 'answer' was not declared in this scope
   67 |         answer(c,x,y);
      |         ^~~~~~
doll.cpp:71:16: error: expected primary-expression before 'int'
   71 |         vector<int> c(m+1),x,y;
      |                ^~~
doll.cpp:72:9: error: 'c' was not declared in this scope
   72 |         c[0]=a[0];
      |         ^
doll.cpp:73:16: error: 'tree' was not declared in this scope
   73 |         vector<tree> v(m+1);
      |                ^~~~
doll.cpp:73:22: error: 'v' was not declared in this scope
   73 |         vector<tree> v(m+1);
      |                      ^
doll.cpp:74:45: error: 'cnt' was not declared in this scope; did you mean 'int'?
   74 |         for (int i=1; i<=m; ++i) v[i].build(cnt[i],cnt[i]);
      |                                             ^~~
      |                                             int
doll.cpp:100:20: error: 'x' was not declared in this scope
  100 |             int sz=x.size();
      |                    ^
doll.cpp:102:33: error: 'y' was not declared in this scope
  102 |             for (auto Y:v[i].y) y.push_back( Y>=0 ? Y : (Y-sz) );
      |                                 ^
doll.cpp:105:18: error: 'x' was not declared in this scope
  105 |         answer(c,x,y);
      |                  ^
doll.cpp:105:20: error: 'y' was not declared in this scope
  105 |         answer(c,x,y);
      |                    ^
doll.cpp:105:9: error: 'answer' was not declared in this scope
  105 |         answer(c,x,y);
      |         ^~~~~~