Submission #1070473

# Submission time Handle Problem Language Result Execution time Memory
1070473 2024-08-22T14:35:11 Z andrei_iorgulescu Counting Mushrooms (IOI20_mushrooms) C++14
82.1818 / 100
15 ms 676 KB
#include <bits/stdc++.h>
#include "mushrooms.h"
#warning That's not FB, that's my FB

using namespace std;

int count_mushrooms(int n)
{
    srand(2082);
    vector<int> A, B;
    A.push_back(0);
    if (n <= 227)
    {
        int ans = 1;
        for (int i = 1; i < n; i++)
            ans += 1 - use_machine({0,i});
        return ans;
    }
    for (int i = 1; i <= 30; i++)
    {
        vector<int> idd;
        for (int j = 0; j < n; j++)
            idd.push_back(j);
        shuffle(idd.begin(), idd.end(), default_random_engine(rand()));
        while (idd.size() > 1500)
            idd.pop_back();
        int xxx = use_machine(idd);
    }
    int hh = use_machine({0,1}), hhh = use_machine({0,2});
    if (hh == 0)
        A.push_back(1);
    else
        B.push_back(1);
    if (hh == 1)
    {
        if (hhh == 0)
            A.push_back(2);
        else
            B.push_back(2);
    }
    int a = A.size(), b = B.size();
    ///caut cel mai bun max(a,b) la care sa ma opresc din spamat
    int best, omin = 1e9;
    for (int i = 5; i <= 1000 and 2 * i <= n; i++)
    {
        int cur = i - 1;
        int cate = n - 2 * i - 1;
        int j = -1;
        while (cate > 0)
        {
            j++;
            cur++;
            cate -= (i + j / 2);
        }
        if (cur < omin)
        {
            omin = cur;
            best = i;
        }
    }
    best--;
    vector<int> unsolved;
    if (hh == 1)
    {
        for (int i = 3; i < n; i++)
            unsolved.push_back(i);
    }
    else
    {
        for (int i = 2; i < n; i++)
            unsolved.push_back(i);
    }
    reverse(unsolved.begin(),unsolved.end());
    while (max(a,b) < best)
    {
        if (a >= 2)
        {
            vector<int> mac = {unsolved[unsolved.size() - 1], A[0], unsolved[unsolved.size() - 2], A[1]};
            int xxx = use_machine(mac);
            if (xxx == 0)
            {
                A.push_back(unsolved.back());
                unsolved.pop_back();
                A.push_back(unsolved.back());
                unsolved.pop_back();
            }
            else if (xxx == 1)
            {
                B.push_back(unsolved.back());
                unsolved.pop_back();
                A.push_back(unsolved.back());
                unsolved.pop_back();
            }
            else if (xxx == 2)
            {
                A.push_back(unsolved.back());
                unsolved.pop_back();
                B.push_back(unsolved.back());
                unsolved.pop_back();
            }
            else
            {
                B.push_back(unsolved.back());
                unsolved.pop_back();
                B.push_back(unsolved.back());
                unsolved.pop_back();
            }
        }
        else
        {
            vector<int> mac = {unsolved[unsolved.size() - 1], B[0], unsolved[unsolved.size() - 2], B[1]};
            int xxx = use_machine(mac);
            if (xxx == 0)
            {
                B.push_back(unsolved.back());
                unsolved.pop_back();
                B.push_back(unsolved.back());
                unsolved.pop_back();
            }
            else if (xxx == 1)
            {
                A.push_back(unsolved.back());
                unsolved.pop_back();
                B.push_back(unsolved.back());
                unsolved.pop_back();
            }
            else if (xxx == 2)
            {
                B.push_back(unsolved.back());
                unsolved.pop_back();
                A.push_back(unsolved.back());
                unsolved.pop_back();
            }
            else
            {
                A.push_back(unsolved.back());
                unsolved.pop_back();
                A.push_back(unsolved.back());
                unsolved.pop_back();
            }
        }
        a = A.size();
        b = B.size();
    }
    int ans = A.size();
    while (!unsolved.empty())
    {
        int k = max(a,b);
        vector<int> cr;
        for (int i = 0; i < k; i++)
        {
            if (!unsolved.empty())
            {
                cr.push_back(unsolved.back());
                unsolved.pop_back();
            }
        }
        if (a >= b)
        {
            vector<int> tq;
            for (int i = 0; i < cr.size(); i++)
            {
                tq.push_back(cr[i]);
                tq.push_back(A[i]);
            }
            int xxx = use_machine(tq);
            if (xxx % 2 == 1)
                B.push_back(cr[0]), xxx--;
            else
                A.push_back(cr[0]), ans++;
            ans += (2 * ((int)cr.size() - 1) - xxx) / 2;
        }
        else
        {
            vector<int> tq;
            for (int i = 0; i < cr.size(); i++)
            {
                tq.push_back(cr[i]);
                tq.push_back(B[i]);
            }
            int xxx = use_machine(tq);
            if (xxx % 2 == 1)
                A.push_back(cr[0]), ans++, xxx--;
            else
                B.push_back(cr[0]);
            ans += xxx / 2;
        }
        a = A.size();
        b = B.size();
    }
    return ans;
}

/**
Aflu sa zicem doua A-uri, dau spamez AxAy ca unic determina x si y, candva ma opresc
Sa zicem ca am a A-uri si b B-uri
While (mai am nedescoperite)
{
k = max(a,b);
Bag x1Ax2A...xkA, astfel aflu cate din x sunt A-uri dar aflu si exact cum e x1, il bag in A-uri sau B-uri si dau a++ sau b++
}

Fara ultima optimizare era fix 2sqrt, asa idk, doamne ajuta
**/

Compilation message

mushrooms.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
    3 | #warning That's not FB, that's my FB
      |  ^~~~~~~
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:27:13: warning: unused variable 'xxx' [-Wunused-variable]
   27 |         int xxx = use_machine(idd);
      |             ^~~
mushrooms.cpp:161:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  161 |             for (int i = 0; i < cr.size(); i++)
      |                             ~~^~~~~~~~~~~
mushrooms.cpp:176:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  176 |             for (int i = 0; i < cr.size(); i++)
      |                             ~~^~~~~~~~~~~
mushrooms.cpp:61:9: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |     best--;
      |     ~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 5 ms 464 KB Output is correct
7 Correct 11 ms 600 KB Output is correct
8 Correct 12 ms 600 KB Output is correct
9 Correct 11 ms 676 KB Output is correct
10 Partially correct 11 ms 600 KB Output is partially correct
11 Partially correct 11 ms 600 KB Output is partially correct
12 Partially correct 11 ms 600 KB Output is partially correct
13 Correct 11 ms 596 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Partially correct 11 ms 600 KB Output is partially correct
16 Partially correct 11 ms 668 KB Output is partially correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 14 ms 600 KB Output is correct
19 Partially correct 12 ms 668 KB Output is partially correct
20 Partially correct 14 ms 600 KB Output is partially correct
21 Partially correct 12 ms 600 KB Output is partially correct
22 Partially correct 11 ms 600 KB Output is partially correct
23 Correct 12 ms 668 KB Output is correct
24 Correct 7 ms 344 KB Output is correct
25 Partially correct 11 ms 600 KB Output is partially correct
26 Partially correct 11 ms 600 KB Output is partially correct
27 Partially correct 11 ms 600 KB Output is partially correct
28 Partially correct 11 ms 596 KB Output is partially correct
29 Partially correct 11 ms 600 KB Output is partially correct
30 Partially correct 11 ms 600 KB Output is partially correct
31 Partially correct 12 ms 600 KB Output is partially correct
32 Partially correct 11 ms 600 KB Output is partially correct
33 Partially correct 11 ms 676 KB Output is partially correct
34 Partially correct 11 ms 600 KB Output is partially correct
35 Partially correct 11 ms 600 KB Output is partially correct
36 Partially correct 11 ms 672 KB Output is partially correct
37 Partially correct 11 ms 600 KB Output is partially correct
38 Partially correct 13 ms 672 KB Output is partially correct
39 Partially correct 11 ms 600 KB Output is partially correct
40 Partially correct 11 ms 600 KB Output is partially correct
41 Partially correct 11 ms 596 KB Output is partially correct
42 Partially correct 15 ms 600 KB Output is partially correct
43 Partially correct 15 ms 600 KB Output is partially correct
44 Partially correct 11 ms 600 KB Output is partially correct
45 Partially correct 11 ms 600 KB Output is partially correct
46 Partially correct 11 ms 672 KB Output is partially correct
47 Partially correct 11 ms 600 KB Output is partially correct
48 Partially correct 12 ms 600 KB Output is partially correct
49 Partially correct 11 ms 600 KB Output is partially correct
50 Partially correct 13 ms 672 KB Output is partially correct
51 Partially correct 11 ms 600 KB Output is partially correct
52 Partially correct 11 ms 668 KB Output is partially correct
53 Partially correct 11 ms 600 KB Output is partially correct
54 Partially correct 11 ms 600 KB Output is partially correct
55 Partially correct 11 ms 600 KB Output is partially correct
56 Partially correct 15 ms 600 KB Output is partially correct
57 Partially correct 11 ms 600 KB Output is partially correct
58 Partially correct 11 ms 600 KB Output is partially correct
59 Partially correct 11 ms 668 KB Output is partially correct
60 Partially correct 11 ms 676 KB Output is partially correct
61 Partially correct 11 ms 672 KB Output is partially correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 0 ms 396 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 0 ms 344 KB Output is correct
77 Correct 0 ms 344 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 0 ms 344 KB Output is correct
81 Correct 0 ms 344 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 0 ms 344 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 1 ms 344 KB Output is correct
86 Correct 0 ms 344 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 0 ms 344 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct