Submission #309155

# Submission time Handle Problem Language Result Execution time Memory
309155 2020-10-02T19:16:42 Z Vimmer Counting Mushrooms (IOI20_mushrooms) C++14
0 / 100
2000 ms 384 KB
#include <bits/stdc++.h>
#include "mushrooms.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define N 100005
#define PB push_back
#define sz(x) int(x.size())
#define F first
#define M ll(1e9 + 7)
#define S second
#define all(x) x.begin(), x.end()
#define endl '\n'

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
//typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int val[N], kol, sum = 0;

//int use_machine(vector <int> &pr)
//{
//
//    set <int> se; se.clear();
//
//    sum += sz(pr);
//
//    if (sz(pr) < 2) exit(0);
//
//    kol++;
//
//    int ans = 0;
//
//    for (int i = 1; i < sz(pr); i++)
//        if (val[pr[i]] != val[pr[i - 1]]) ans++;
//
//    if (kol < 4) {for (auto it : pr) cout << it << " "; cout << endl; cout << ans << endl;}
//
//    return ans;
//}

int skok = 100;

int ask(vector <int> &m) { return use_machine(m);}
int ask(set <int> &se) {vector <int> m; m.clear(); for (auto it : se) m.PB(it); return use_machine(m);}

ll mlt(ll x, ll y) {return (x * y) % M;}
ll sm(ll x, ll y) {return (x + y) % M;}

vector <int> tr, tl;

int es_minus_3(set <int> &se)
{
    int ans = sz(tr);

    while (sz(se) > 0)
    {
        int i = 0;

        vector <int> m; m.clear();

        if (sz(tr) > sz(tl))
        {
            while (i < sz(tr) && sz(se) > 0)
            {
                m.PB(tr[i++]);

                m.PB(*se.begin());

                se.erase(se.begin());
            }

            int val = ask(m);

            int koler = (sz(m) / 2) - (val / 2);

            if (val % 2) {koler--; tl.PB(m.back());}
              else tr.PB(m.back());

            ans += koler;
        }
        else
        {
            while (i < sz(tl) && sz(se) > 0)
            {
                m.PB(tl[i++]);

                m.PB(*se.begin());

                se.erase(se.begin());
            }

            int val = ask(m);

            int koler = val / 2;

            if (val % 2) {tr.PB(m.back()); koler++;}
              else tl.PB(m.back());

            ans += koler;
        }
    }

    return ans;
}

void dec(set <int> &se) {se.erase(se.begin());}

int count_mushrooms(int n)
{
    tr.PB(0);

    vector <int> m; m.clear();

    m.PB(0);

    set <int> se; se.clear();

    for (int i = 1; i < n; i++) se.insert(i);

    if (n > 100)
    {
        vector <int> m = {0, *se.begin()};

        dec(se);

        if (ask(m) == 0)
        {
            tr.PB(m.back());

            m.resize(4);

            m[0] = 0;

            m[2] = tr[1];

            m[1] = *se.begin();

            dec(se);

            m[3] = *se.begin();

            dec(se);

            int val = ask(m);

            if (val == 0) {tr.PB(m[1]); tr.PB(m[3]);} else
            if (val == 1) {tr.PB(m[1]); tl.PB(m[3]);} else
            if (val == 2) {tr.PB(m[3]); tl.PB(m[1]);} else
            if (val == 3) {tl.PB(m[1]); tl.PB(m[3]);}

            int i = 0;

            while (i < skok)
            {
                m[1] = *se.begin();

                dec(se);

                m[3] = *se.begin();

                dec(se);

                val = ask(m);

                if (val == 0) {tr.PB(m[1]); tr.PB(m[3]);} else
                if (val == 1) {tr.PB(m[1]); tl.PB(m[3]);} else
                if (val == 2) {tr.PB(m[3]); tl.PB(m[1]);} else
                if (val == 3) {tl.PB(m[1]); tl.PB(m[3]);}

                i++;
            }
        }
        else
        {
            tl.PB(m[1]);

            m[1] = *se.begin();

            dec(se);

            if (ask(m) != 0)
            {
                tl.PB(m[1]);

                m.clear();

                m.PB(tl[0]);

                m.PB(*se.begin());

                dec(se);

                m.PB(tl[1]);

                m.PB(*se.begin());

                dec(se);

                int val = ask(m);

                if (val == 0) {tl.PB(m[1]); tl.PB(m[3]);}
                if (val == 1) {tl.PB(m[1]); tr.PB(m[3]);}
                if (val == 2) {tl.PB(m[3]); tr.PB(m[1]);}
                if (val == 3) {tr.PB(m[1]); tr.PB(m[3]);}

                int i = 0;

                while (i < skok)
                {
                    m[1] = *se.begin(); dec(se);

                    m[3] = *se.begin(); dec(se);

                    val = ask(m);

                    if (val == 0) {tl.PB(m[1]); tl.PB(m[3]);}
                    if (val == 1) {tl.PB(m[1]); tr.PB(m[3]);}
                    if (val == 2) {tl.PB(m[3]); tr.PB(m[1]);}
                    if (val == 3) {tr.PB(m[1]); tr.PB(m[3]);}

                    i++;
                }
            }
            else
            {
                tr.PB(m.back());

                m.resize(4);

                m[0] = 0;

                m[2] = tr[1];

                m[1] = *se.begin();

                dec(se);

                m[3] = *se.begin();

                dec(se);

                int val = ask(m);

                if (val == 0) {tr.PB(m[1]); tr.PB(m[3]);} else
                if (val == 1) {tr.PB(m[1]); tl.PB(m[3]);} else
                if (val == 2) {tr.PB(m[3]); tl.PB(m[1]);} else
                if (val == 3) {tl.PB(m[1]); tl.PB(m[3]);}

                int i = 0;

                while (i < skok)
                {
                    m[1] = *se.begin();

                    dec(se);

                    m[3] = *se.begin();

                    dec(se);

                    val = ask(m);

                    if (val == 0) {tr.PB(m[1]); tr.PB(m[3]);} else
                    if (val == 1) {tr.PB(m[1]); tl.PB(m[3]);} else
                    if (val == 2) {tr.PB(m[3]); tl.PB(m[1]);} else
                    if (val == 3) {tl.PB(m[1]); tl.PB(m[3]);}

                    i++;
                }
            }
        }
    }

    return es_minus_3(se);
}

//int main()
//{
//    iostream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//
//    freopen("1.in", "r", stdin); //freopen("fcolor.out", "w", stdout);
//
//    int n;
//
//    cin >> n;
//
//    int num = 0;
//
//    for (int i = 0; i < n; i++) {cin >> val[i]; if (val[i] == 0) num++;}
//
//    cout << num << endl;
//    cout << count_mushrooms(n) << endl;
//
//
//    cout << kol << " " << sum << endl;
//}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Execution timed out 3077 ms 384 KB Time limit exceeded
6 Halted 0 ms 0 KB -