Submission #299733

#TimeUsernameProblemLanguageResultExecution timeMemory
299733Dremix10Mechanical Doll (IOI18_doll)C++17
Compilation error
0 ms0 KiB
void create_circuit(int m, vector<int> a) {
    int n = a.size();
    /// each trigger can only go to one place
    /// so in the case of {1,2,1} 1 can't go to 2 because
    /// the second time we get to 1 we will go to 2 which
    /// shouldn't happen

    int i,s = 1;
    vector<int> ans(m+1);
    vector<int> x,y;

    int cnt[m+1]={};

    for(auto x : a)
        cnt[x]++;
    int now[m+1]={};

    ans[0] = a[0];
    a.push_back(0);

    /// build circuit /*
    for(i=0;i<n;i++){
        int curr = a[i];
        if(cnt[curr]==1){
            ans[curr] = a[i+1];
        }
        else if(cnt[curr]==2){
            if(!now[curr]){
                ans[curr] = -s;
                s++;
                x.push_back(a[i+1]);
                y.push_back(-1);
                now[curr]++;
            }
            else{
                y[-ans[curr]-1] = a[i+1];
                now[curr]++;
            }
        }
        else if(cnt[curr]==3){
            if(!now[curr]){
                ans[curr] = -s;

                /// creating and directing first switch
                s++;
                x.push_back(-s);
                s++;
                y.push_back(-s);
                s++;

                /// configure second switch
                x.push_back(a[i+1]);
                y.push_back(ans[curr]);

                /// prep third switch
                x.push_back(-1);
                y.push_back(-1);

                now[curr]++;
            }
            else if(now[curr]==1){
                int idx = y[-ans[curr]-1];

                /// configure half third switch
                x[-idx-1] = a[i+1];

                now[curr]++;
            }
            else{
                int idx = y[-ans[curr]-1];

                /// configure other half third switch
                y[-idx-1] = a[i+1];

                now[curr]++;
            }
        }
        else{
            if(!now[curr]){
                ans[curr] = -s;

                /// creating and directing first switch
                s++;
                x.push_back(-s);
                s++;
                y.push_back(-s);
                s++;

                /// configure half second switch + prep other
                x.push_back(a[i+1]);
                y.push_back(-1);

                /// prep third switch
                x.push_back(-1);
                y.push_back(-1);

                now[curr]++;
            }
            else if(now[curr]==1){
                int idx = y[-ans[curr]-1];

                /// configure half third switch
                x[-idx-1] = a[i+1];

                now[curr]++;
            }
            else if(now[curr]==2){
                int idx = x[-ans[curr]-1];

                /// configure other half second switch
                y[-idx-1] = a[i+1];

                now[curr]++;
            }
            else{
                int idx = y[-ans[curr]-1];

                /// configure other half third switch
                y[-idx-1] = a[i+1];

                now[curr]++;
            }
        }
    }
    /// build circuit */

    for(i=1;i<=m;i++)
        if(!cnt[i])ans[i] = i;
    answer(ans,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:13: error: 'a' was not declared in this scope
    2 |     int n = a.size();
      |             ^
doll.cpp:9:5: error: 'vector' was not declared in this scope
    9 |     vector<int> ans(m+1);
      |     ^~~~~~
doll.cpp:9:12: error: expected primary-expression before 'int'
    9 |     vector<int> ans(m+1);
      |            ^~~
doll.cpp:10:12: error: expected primary-expression before 'int'
   10 |     vector<int> x,y;
      |            ^~~
doll.cpp:18:5: error: 'ans' was not declared in this scope
   18 |     ans[0] = a[0];
      |     ^~~
doll.cpp:31:17: error: 'x' was not declared in this scope
   31 |                 x.push_back(a[i+1]);
      |                 ^
doll.cpp:32:17: error: 'y' was not declared in this scope
   32 |                 y.push_back(-1);
      |                 ^
doll.cpp:36:17: error: 'y' was not declared in this scope
   36 |                 y[-ans[curr]-1] = a[i+1];
      |                 ^
doll.cpp:46:17: error: 'x' was not declared in this scope
   46 |                 x.push_back(-s);
      |                 ^
doll.cpp:48:17: error: 'y' was not declared in this scope
   48 |                 y.push_back(-s);
      |                 ^
doll.cpp:62:27: error: 'y' was not declared in this scope
   62 |                 int idx = y[-ans[curr]-1];
      |                           ^
doll.cpp:65:17: error: 'x' was not declared in this scope
   65 |                 x[-idx-1] = a[i+1];
      |                 ^
doll.cpp:70:27: error: 'y' was not declared in this scope
   70 |                 int idx = y[-ans[curr]-1];
      |                           ^
doll.cpp:84:17: error: 'x' was not declared in this scope
   84 |                 x.push_back(-s);
      |                 ^
doll.cpp:86:17: error: 'y' was not declared in this scope
   86 |                 y.push_back(-s);
      |                 ^
doll.cpp:100:27: error: 'y' was not declared in this scope
  100 |                 int idx = y[-ans[curr]-1];
      |                           ^
doll.cpp:103:17: error: 'x' was not declared in this scope
  103 |                 x[-idx-1] = a[i+1];
      |                 ^
doll.cpp:108:27: error: 'x' was not declared in this scope
  108 |                 int idx = x[-ans[curr]-1];
      |                           ^
doll.cpp:111:17: error: 'y' was not declared in this scope
  111 |                 y[-idx-1] = a[i+1];
      |                 ^
doll.cpp:116:27: error: 'y' was not declared in this scope
  116 |                 int idx = y[-ans[curr]-1];
      |                           ^
doll.cpp:129:16: error: 'x' was not declared in this scope
  129 |     answer(ans,x,y);
      |                ^
doll.cpp:129:18: error: 'y' was not declared in this scope
  129 |     answer(ans,x,y);
      |                  ^
doll.cpp:129:5: error: 'answer' was not declared in this scope
  129 |     answer(ans,x,y);
      |     ^~~~~~