Submission #309086

# Submission time Handle Problem Language Result Execution time Memory
309086 2020-10-02T18:06:35 Z Vimmer Counting Mushrooms (IOI20_mushrooms) C++14
53.6817 / 100
28 ms 1864 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)
//{
//    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++;
//
//    return ans;
//}

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;}

int NEED = 100, nr;

vector <int> tr, tl;

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

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

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

            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--;

            ans += koler;
        }
    }
    else
    {
        while (sz(se) > 0)
        {
            int i = 0;

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

            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) koler++;

            ans += koler;
        }
    }

    return ans;
}

void fnd(set <int> &se)
{
    if (sz(se) < 4) return;

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

    int nm = sz(se) / 2;

    while (sz(st) < nm) {st.insert(*se.begin()); se.erase(se.begin());}

    int val1 = ask(st), val2;

    if (val1 == 0)
    {
        st.insert(0);

        if (ask(st) == 0) {st.erase(0); for (auto it : st) tr.PB(it);}
          else {st.erase(0); for (auto it : st) tl.PB(it);}

        st.clear();
    }
    else
    {
        val2 = ask(se);

        if (val2 == 0)
        {
            se.insert(0);

            if (ask(se) == 0) {se.erase(0); for (auto it : se) tr.PB(it);}
              else {se.erase(0); for (auto it : se) tl.PB(it);}

            se.clear();
        }
        else
        {
          if (val1 > val2) fnd(se);
            else fnd(st);
        }
    }

    for (auto it : st) se.insert(it);
}

int count_mushrooms(int n)
{
    nr = 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 >= 10000) fnd(se);

    int i = 1;

    while (i < n && sz(tr) < NEED && sz(tl) < NEED)
    {
        m.PB(i);

        int val = ask(m);

        m.pop_back();

        se.erase(i);

        if (val == 1) tl.PB(i++); else tr.PB(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 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 18 ms 1580 KB Output is correct
8 Correct 21 ms 1712 KB Output is correct
9 Partially correct 22 ms 1708 KB Output is partially correct
10 Partially correct 25 ms 1728 KB Output is partially correct
11 Partially correct 24 ms 1728 KB Output is partially correct
12 Partially correct 28 ms 1744 KB Output is partially correct
13 Partially correct 23 ms 1716 KB Output is partially correct
14 Partially correct 13 ms 1000 KB Output is partially correct
15 Partially correct 23 ms 1720 KB Output is partially correct
16 Partially correct 24 ms 1708 KB Output is partially correct
17 Partially correct 12 ms 996 KB Output is partially correct
18 Partially correct 22 ms 1704 KB Output is partially correct
19 Partially correct 24 ms 1724 KB Output is partially correct
20 Partially correct 23 ms 1700 KB Output is partially correct
21 Partially correct 26 ms 1740 KB Output is partially correct
22 Partially correct 23 ms 1716 KB Output is partially correct
23 Partially correct 24 ms 1720 KB Output is partially correct
24 Partially correct 13 ms 996 KB Output is partially correct
25 Partially correct 25 ms 1720 KB Output is partially correct
26 Partially correct 23 ms 1720 KB Output is partially correct
27 Partially correct 23 ms 1708 KB Output is partially correct
28 Partially correct 28 ms 1716 KB Output is partially correct
29 Partially correct 25 ms 1724 KB Output is partially correct
30 Partially correct 25 ms 1728 KB Output is partially correct
31 Partially correct 23 ms 1708 KB Output is partially correct
32 Partially correct 24 ms 1720 KB Output is partially correct
33 Partially correct 22 ms 1816 KB Output is partially correct
34 Partially correct 27 ms 1712 KB Output is partially correct
35 Partially correct 23 ms 1716 KB Output is partially correct
36 Partially correct 26 ms 1732 KB Output is partially correct
37 Partially correct 24 ms 1704 KB Output is partially correct
38 Partially correct 28 ms 1736 KB Output is partially correct
39 Partially correct 22 ms 1808 KB Output is partially correct
40 Partially correct 23 ms 1720 KB Output is partially correct
41 Partially correct 24 ms 1716 KB Output is partially correct
42 Partially correct 23 ms 1712 KB Output is partially correct
43 Partially correct 24 ms 1716 KB Output is partially correct
44 Partially correct 23 ms 1836 KB Output is partially correct
45 Partially correct 23 ms 1716 KB Output is partially correct
46 Partially correct 26 ms 1728 KB Output is partially correct
47 Partially correct 25 ms 1720 KB Output is partially correct
48 Partially correct 27 ms 1864 KB Output is partially correct
49 Partially correct 24 ms 1728 KB Output is partially correct
50 Partially correct 23 ms 1720 KB Output is partially correct
51 Partially correct 25 ms 1724 KB Output is partially correct
52 Partially correct 23 ms 1716 KB Output is partially correct
53 Partially correct 23 ms 1720 KB Output is partially correct
54 Partially correct 24 ms 1716 KB Output is partially correct
55 Partially correct 26 ms 1720 KB Output is partially correct
56 Partially correct 25 ms 1716 KB Output is partially correct
57 Partially correct 24 ms 1724 KB Output is partially correct
58 Partially correct 24 ms 1708 KB Output is partially correct
59 Partially correct 24 ms 1720 KB Output is partially correct
60 Partially correct 23 ms 1716 KB Output is partially correct
61 Partially correct 25 ms 1844 KB Output is partially correct
62 Correct 0 ms 256 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 0 ms 256 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 0 ms 384 KB Output is correct
68 Correct 0 ms 384 KB Output is correct
69 Correct 0 ms 256 KB Output is correct
70 Correct 0 ms 384 KB Output is correct
71 Correct 0 ms 256 KB Output is correct
72 Correct 0 ms 256 KB Output is correct
73 Correct 0 ms 384 KB Output is correct
74 Correct 0 ms 256 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 0 ms 256 KB Output is correct
81 Correct 1 ms 256 KB Output is correct
82 Correct 0 ms 384 KB Output is correct
83 Correct 0 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 0 ms 256 KB Output is correct
86 Correct 0 ms 256 KB Output is correct
87 Correct 0 ms 384 KB Output is correct
88 Correct 0 ms 256 KB Output is correct
89 Correct 0 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 0 ms 256 KB Output is correct