Submission #817742

# Submission time Handle Problem Language Result Execution time Memory
817742 2023-08-09T15:29:35 Z math_rabbit_1028 Counting Mushrooms (IOI20_mushrooms) C++14
100 / 100
7 ms 332 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

int count_mushrooms(int n) {
    int b = 106;
    vector<int> Alist, Blist;
    Alist.push_back(0);
    int i, ans = Alist.size();

    if (n <= 200) {
        for (int i = 1; i < n; i++) if (use_machine({Alist[0], i}) == 0) ans++;
        return ans;
    }

    if (use_machine({0, 1}) == 0) {
        Alist.push_back(1);
        for (i = 2; i < n; i += 2) {
            int ret = use_machine({Alist[0], i, Alist[1], i + 1});
            if (ret >= 2) Blist.push_back(i);
            else Alist.push_back(i);
            if (ret % 2 == 0) Alist.push_back(i + 1);
            else Blist.push_back(i + 1);
            if (Alist.size() >= 3 && Blist.size() >= 2) break;
            if (Alist.size() >= 2 && Blist.size() >= 3) break;
            if (Alist.size() >= b || Blist.size() >= b) break;
        }
    }
    else {
        Blist.push_back(1);
        if (use_machine({0, 2}) == 0) {
            Alist.push_back(2);
            for (i = 3; i < n; i += 2) {
                int ret = use_machine({Alist[0], i, Alist[1], i + 1});
                if (ret >= 2) Blist.push_back(i);
                else Alist.push_back(i);
                if (ret % 2 == 0) Alist.push_back(i + 1);
                else Blist.push_back(i + 1);
                if (Alist.size() >= 3 && Blist.size() >= 2) break;
                if (Alist.size() >= 2 && Blist.size() >= 3) break;
                if (Alist.size() >= b || Blist.size() >= b) break;
            }
        }
        else {
            Blist.push_back(2);
            for (i = 3; i < n; i += 2) {
                int ret = use_machine({Blist[0], i, Blist[1], i + 1});
                if (ret >= 2) Alist.push_back(i);
                else Blist.push_back(i);
                if (ret % 2 == 0) Blist.push_back(i + 1);
                else Alist.push_back(i + 1);
                if (Alist.size() >= 3 && Blist.size() >= 2) break;
                if (Alist.size() >= 2 && Blist.size() >= 3) break;
                if (Alist.size() >= b || Blist.size() >= b) break;
            }
        }
    }

    i += 2;
    if (Alist.size() >= 3 && Blist.size() >= 2) {
        for (; i < n; i += 5) {
            int ret = use_machine({Alist[0], i, Alist[1], i + 1, Alist[2], i + 2}), ret2;
            if (ret == 0) {
                Alist.push_back(i);
                Alist.push_back(i + 1);
                Alist.push_back(i + 2);
            }
            if (ret == 1) {
                Alist.push_back(i);
                Alist.push_back(i + 1);
                Blist.push_back(i + 2);
            }
            if (ret == 4) {
                Blist.push_back(i);
                Blist.push_back(i + 1);
                Alist.push_back(i + 2);
            }
            if (ret == 5) {
                Blist.push_back(i);
                Blist.push_back(i + 1);
                Blist.push_back(i + 2);
            }
            if (ret == 0 || ret == 1 || ret == 4 || ret == 5) {
                ret2 = use_machine({Alist[0], i + 3, Alist[1], i + 4});
            }

            if (ret == 2 || ret == 3) {
                ret2 = use_machine({Blist[0], i, Blist[1], Alist[0], i + 1, Alist[1], i + 3, Alist[2], i + 4}) - 1;
                if (ret2 >= 4) {
                    Alist.push_back(i);
                    Blist.push_back(i + 1);
                    ret2 -= 4;
                }
                else {
                    Blist.push_back(i);
                    Alist.push_back(i + 1);
                }
                if (ret == 2) Alist.push_back(i + 2);
                if (ret == 3) Blist.push_back(i + 2);
            }

            if (ret2 >= 2) Blist.push_back(i + 3);
            else Alist.push_back(i + 3);
            if (ret2 % 2 == 0) Alist.push_back(i + 4);
            else Blist.push_back(i + 4);

            if (Alist.size() >= b || Blist.size() >= b) break;
        }
        i += 5;
    }
    else if (Alist.size() >= 2 && Blist.size() >= 3) {
        for (; i < n; i += 5) {
            int ret = use_machine({Blist[0], i, Blist[1], i + 1, Blist[2], i + 2}), ret2;
            if (ret == 0) {
                Blist.push_back(i);
                Blist.push_back(i + 1);
                Blist.push_back(i + 2);
            }
            if (ret == 1) {
                Blist.push_back(i);
                Blist.push_back(i + 1);
                Alist.push_back(i + 2);
            }
            if (ret == 4) {
                Alist.push_back(i);
                Alist.push_back(i + 1);
                Blist.push_back(i + 2);
            }
            if (ret == 5) {
                Alist.push_back(i);
                Alist.push_back(i + 1);
                Alist.push_back(i + 2);
            }
            if (ret == 0 || ret == 1 || ret == 4 || ret == 5) {
                ret2 = use_machine({Blist[0], i + 3, Blist[1], i + 4});
            }

            if (ret == 2 || ret == 3) {
                ret2 = use_machine({Alist[0], i, Alist[1], Blist[0], i + 1, Blist[1], i + 3, Blist[2], i + 4}) - 1;
                if (ret2 >= 4) {
                    Blist.push_back(i);
                    Alist.push_back(i + 1);
                    ret2 -= 4;
                }
                else {
                    Alist.push_back(i);
                    Blist.push_back(i + 1);
                }
                if (ret == 2) Blist.push_back(i + 2);
                if (ret == 3) Alist.push_back(i + 2);
            }

            if (ret2 >= 2) Alist.push_back(i + 3);
            else Blist.push_back(i + 3);
            if (ret2 % 2 == 0) Blist.push_back(i + 4);
            else Alist.push_back(i + 4);

            if (Alist.size() >= b || Blist.size() >= b) break;
        }
        i += 5;
    }

    ans = Alist.size();
    for (; i < n; ) {
        vector<int> seq;
        if (Alist.size() >= Blist.size()) {
            for (int j = i; j < min(i + (int)Alist.size(), n); j++) {
                seq.push_back(Alist[j - i]);
                seq.push_back(j);
            }
            int ret = use_machine(seq);
            ans += (min(i + (int)Alist.size(), n) - i) - (ret + 1) / 2;
            i += Alist.size();
            if (ret % 2 == 0) Alist.push_back(i - 1);
            if (ret % 2 == 1) Blist.push_back(i - 1);
        }
        else {
            for (int j = i; j < min(i + (int)Blist.size(), n); j++) {
                seq.push_back(Blist[j - i]);
                seq.push_back(j);
            }
            int ret = use_machine(seq);
            ans += (ret + 1) / 2;
            i += Blist.size();
            if (ret % 2 == 0) Blist.push_back(i - 1);
            if (ret % 2 == 1) Alist.push_back(i - 1);
        }
    }
    return ans;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:26:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |             if (Alist.size() >= b || Blist.size() >= b) break;
      |                 ~~~~~~~~~~~~~^~~~
mushrooms.cpp:26:51: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |             if (Alist.size() >= b || Blist.size() >= b) break;
      |                                      ~~~~~~~~~~~~~^~~~
mushrooms.cpp:41:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |                 if (Alist.size() >= b || Blist.size() >= b) break;
      |                     ~~~~~~~~~~~~~^~~~
mushrooms.cpp:41:55: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |                 if (Alist.size() >= b || Blist.size() >= b) break;
      |                                          ~~~~~~~~~~~~~^~~~
mushrooms.cpp:54:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |                 if (Alist.size() >= b || Blist.size() >= b) break;
      |                     ~~~~~~~~~~~~~^~~~
mushrooms.cpp:54:55: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |                 if (Alist.size() >= b || Blist.size() >= b) break;
      |                                          ~~~~~~~~~~~~~^~~~
mushrooms.cpp:107:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |             if (Alist.size() >= b || Blist.size() >= b) break;
      |                 ~~~~~~~~~~~~~^~~~
mushrooms.cpp:107:51: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |             if (Alist.size() >= b || Blist.size() >= b) break;
      |                                      ~~~~~~~~~~~~~^~~~
mushrooms.cpp:158:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  158 |             if (Alist.size() >= b || Blist.size() >= b) break;
      |                 ~~~~~~~~~~~~~^~~~
mushrooms.cpp:158:51: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  158 |             if (Alist.size() >= b || Blist.size() >= b) break;
      |                                      ~~~~~~~~~~~~~^~~~
mushrooms.cpp:155:26: warning: 'ret2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  155 |             if (ret2 % 2 == 0) Blist.push_back(i + 4);
      |                 ~~~~~~~~~^~~~
mushrooms.cpp:104:26: warning: 'ret2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  104 |             if (ret2 % 2 == 0) Alist.push_back(i + 4);
      |                 ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 308 KB Output is correct
10 Correct 4 ms 308 KB Output is correct
11 Correct 5 ms 208 KB Output is correct
12 Correct 5 ms 320 KB Output is correct
13 Correct 4 ms 320 KB Output is correct
14 Correct 4 ms 316 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 5 ms 316 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 6 ms 208 KB Output is correct
21 Correct 5 ms 208 KB Output is correct
22 Correct 5 ms 324 KB Output is correct
23 Correct 5 ms 208 KB Output is correct
24 Correct 3 ms 208 KB Output is correct
25 Correct 7 ms 316 KB Output is correct
26 Correct 5 ms 320 KB Output is correct
27 Correct 5 ms 208 KB Output is correct
28 Correct 5 ms 208 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 5 ms 208 KB Output is correct
31 Correct 5 ms 308 KB Output is correct
32 Correct 6 ms 308 KB Output is correct
33 Correct 5 ms 312 KB Output is correct
34 Correct 5 ms 208 KB Output is correct
35 Correct 5 ms 208 KB Output is correct
36 Correct 5 ms 320 KB Output is correct
37 Correct 5 ms 208 KB Output is correct
38 Correct 5 ms 308 KB Output is correct
39 Correct 5 ms 208 KB Output is correct
40 Correct 5 ms 208 KB Output is correct
41 Correct 5 ms 316 KB Output is correct
42 Correct 6 ms 320 KB Output is correct
43 Correct 7 ms 324 KB Output is correct
44 Correct 6 ms 312 KB Output is correct
45 Correct 5 ms 208 KB Output is correct
46 Correct 5 ms 208 KB Output is correct
47 Correct 5 ms 208 KB Output is correct
48 Correct 4 ms 308 KB Output is correct
49 Correct 5 ms 208 KB Output is correct
50 Correct 5 ms 320 KB Output is correct
51 Correct 5 ms 208 KB Output is correct
52 Correct 5 ms 316 KB Output is correct
53 Correct 5 ms 208 KB Output is correct
54 Correct 7 ms 316 KB Output is correct
55 Correct 5 ms 328 KB Output is correct
56 Correct 7 ms 208 KB Output is correct
57 Correct 5 ms 208 KB Output is correct
58 Correct 5 ms 312 KB Output is correct
59 Correct 5 ms 208 KB Output is correct
60 Correct 5 ms 320 KB Output is correct
61 Correct 5 ms 320 KB Output is correct
62 Correct 0 ms 208 KB Output is correct
63 Correct 0 ms 208 KB Output is correct
64 Correct 0 ms 208 KB Output is correct
65 Correct 0 ms 208 KB Output is correct
66 Correct 0 ms 208 KB Output is correct
67 Correct 0 ms 208 KB Output is correct
68 Correct 0 ms 208 KB Output is correct
69 Correct 0 ms 208 KB Output is correct
70 Correct 0 ms 208 KB Output is correct
71 Correct 0 ms 208 KB Output is correct
72 Correct 0 ms 208 KB Output is correct
73 Correct 0 ms 208 KB Output is correct
74 Correct 0 ms 208 KB Output is correct
75 Correct 0 ms 208 KB Output is correct
76 Correct 0 ms 208 KB Output is correct
77 Correct 0 ms 208 KB Output is correct
78 Correct 1 ms 208 KB Output is correct
79 Correct 0 ms 208 KB Output is correct
80 Correct 1 ms 208 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 0 ms 208 KB Output is correct
83 Correct 0 ms 208 KB Output is correct
84 Correct 0 ms 208 KB Output is correct
85 Correct 0 ms 208 KB Output is correct
86 Correct 1 ms 208 KB Output is correct
87 Correct 0 ms 208 KB Output is correct
88 Correct 0 ms 208 KB Output is correct
89 Correct 0 ms 208 KB Output is correct
90 Correct 0 ms 208 KB Output is correct
91 Correct 0 ms 208 KB Output is correct