Submission #725670

#TimeUsernameProblemLanguageResultExecution timeMemory
725670aykhnRarest Insects (IOI22_insects)C++17
Compilation error
0 ms0 KiB
int min_cardinality(int n)
{

    int sz = 0;

    vector<int> out;

    for (int i = 0; i < n; i++)
    {
        move_inside(i);
        int x = press_button();
        if (x > 1)
        {
            move_outside(i);
            out.pb(i);
        }
        else sz++;
    }

    int best = 1;
    int rn = sz;
    int l = 2;
    int r = n/sz;

    while (l <= r)
    {
        int mid = (l + r) >> 1;
        vector<int> temp;
        vector<int> nout;

        for (int i = 0; i < out.size(); i++)
        {
            move_inside(out[i]);
            int x = press_button();
            if (x > mid)
            {
                nout.pb(out[i]);
                move_outside(out[i]);
            }
            else
            {
                rn++;
                temp.pb(out[i]);
            }
            if (rn == mid * sz)
            { // fill out to next out (nout)
                for (int j = i + 1; j < out.size(); j++) nout.pb(out[j]);
                break;
            }
        }
 // if true, previous elements not needed
 // current elements not needed ?? yes

        if (rn == mid * sz)
        {
            best = max(best, mid);
            l = mid + 1;
            out = nout;
        }
        else
        {
            r = mid - 1;
            for (int x : temp) move_outside(x);
        }
    }

    return best;
}

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:6:5: error: 'vector' was not declared in this scope
    6 |     vector<int> out;
      |     ^~~~~~
insects.cpp:6:12: error: expected primary-expression before 'int'
    6 |     vector<int> out;
      |            ^~~
insects.cpp:10:9: error: 'move_inside' was not declared in this scope
   10 |         move_inside(i);
      |         ^~~~~~~~~~~
insects.cpp:11:17: error: 'press_button' was not declared in this scope
   11 |         int x = press_button();
      |                 ^~~~~~~~~~~~
insects.cpp:14:13: error: 'move_outside' was not declared in this scope
   14 |             move_outside(i);
      |             ^~~~~~~~~~~~
insects.cpp:15:13: error: 'out' was not declared in this scope
   15 |             out.pb(i);
      |             ^~~
insects.cpp:28:16: error: expected primary-expression before 'int'
   28 |         vector<int> temp;
      |                ^~~
insects.cpp:29:16: error: expected primary-expression before 'int'
   29 |         vector<int> nout;
      |                ^~~
insects.cpp:31:29: error: 'out' was not declared in this scope
   31 |         for (int i = 0; i < out.size(); i++)
      |                             ^~~
insects.cpp:33:13: error: 'move_inside' was not declared in this scope
   33 |             move_inside(out[i]);
      |             ^~~~~~~~~~~
insects.cpp:34:21: error: 'press_button' was not declared in this scope
   34 |             int x = press_button();
      |                     ^~~~~~~~~~~~
insects.cpp:37:17: error: 'nout' was not declared in this scope
   37 |                 nout.pb(out[i]);
      |                 ^~~~
insects.cpp:38:17: error: 'move_outside' was not declared in this scope
   38 |                 move_outside(out[i]);
      |                 ^~~~~~~~~~~~
insects.cpp:43:17: error: 'temp' was not declared in this scope
   43 |                 temp.pb(out[i]);
      |                 ^~~~
insects.cpp:47:58: error: 'nout' was not declared in this scope
   47 |                 for (int j = i + 1; j < out.size(); j++) nout.pb(out[j]);
      |                                                          ^~~~
insects.cpp:56:20: error: 'max' was not declared in this scope
   56 |             best = max(best, mid);
      |                    ^~~
insects.cpp:58:13: error: 'out' was not declared in this scope
   58 |             out = nout;
      |             ^~~
insects.cpp:58:19: error: 'nout' was not declared in this scope
   58 |             out = nout;
      |                   ^~~~
insects.cpp:63:26: error: 'temp' was not declared in this scope
   63 |             for (int x : temp) move_outside(x);
      |                          ^~~~
insects.cpp:63:32: error: 'move_outside' was not declared in this scope
   63 |             for (int x : temp) move_outside(x);
      |                                ^~~~~~~~~~~~