Submission #414290

# Submission time Handle Problem Language Result Execution time Memory
414290 2021-05-30T09:57:37 Z 79brue Counting Mushrooms (IOI20_mushrooms) C++14
100 / 100
11 ms 380 KB
#include <bits/stdc++.h>
#include "mushrooms.h"

using namespace std;

typedef long long ll;
const int LIM = 115;

int countIfNIsSmall(int n){
    int ans = 1;
    for(int i=1; i<n; i+=2){
        if(i==n-1) ans += 1 - use_machine(vector<int> {i, 0});
        else ans += 2 - use_machine(vector<int> {i, 0, i+1});
    }
    return ans;
}

int n;
int arr[20002];
int pointer = 1;
vector<int> vec[2];
int ans;

int need;

int count_mushrooms(int n){
    if(n<=400) return countIfNIsSmall(n);

    arr[0] = 0;
    while(vec[0].size() < 2 && vec[1].size() < 2){
        if(use_machine(vector<int> {0, pointer}) == 1){
            arr[pointer] = 1;
            vec[1].push_back(pointer);
        }
        else{
            arr[pointer] = 0;
            vec[0].push_back(pointer);
        }
        pointer++;
    }

    while(vec[0].size() < 3 && vec[1].size() < 3){
        int mode = (vec[0].size() >= 2 ? 0 : 1);
        int tmp = use_machine(vector<int> {vec[mode][0], pointer, vec[mode][1], pointer+1});

        arr[pointer] = mode ^ (tmp >= 2);
        vec[arr[pointer]].push_back(pointer);

        arr[pointer+1] = mode ^ (tmp % 2);
        vec[arr[pointer+1]].push_back(pointer+1);

        pointer += 2;
    }

    int counter = 0;
//    while((vec[0].size() < LIM && vec[1].size() < LIM) || need){
    while(++counter <= 75 || need){
        int mode = (vec[0].size() > vec[1].size() ? 0 : 1);
        if(!need){
            int tmp = use_machine(vector<int> {pointer, vec[mode][0], pointer+1, vec[mode][1], pointer+2, vec[mode][2]});

            arr[pointer] = mode ^ (tmp % 2);
            vec[arr[pointer]].push_back(pointer);

            if(tmp/2 == 0){
                arr[pointer+1] = arr[pointer+2] = mode;
                vec[mode].push_back(pointer+1);
                vec[mode].push_back(pointer+2);
            }
            else if(tmp/2 == 2){
                arr[pointer+1] = arr[pointer+2] = !mode;
                vec[!mode].push_back(pointer+1);
                vec[!mode].push_back(pointer+2);
            }
            else{
                need = pointer+2;
            }
            pointer += 3;
        }
        else if((int)vec[!mode].size() >= 2){
            int tmp = use_machine(vector<int> {vec[!mode][0], need-1, vec[!mode][1], vec[mode][0], need,
                                               vec[mode][1], pointer, vec[mode][2], pointer+1}) - 1;

            if(tmp >= 4){
                arr[need-1] = mode, arr[need] = !mode;
                vec[mode].push_back(need-1);
                vec[!mode].push_back(need);
            }
            else{
                arr[need-1] = !mode, arr[need] = mode;
                vec[mode].push_back(need);
                vec[!mode].push_back(need-1);
            }
            need = 0;
            tmp %= 4;

            arr[pointer] = mode ^ (tmp >= 2);
            vec[arr[pointer]].push_back(pointer);

            arr[pointer+1] = mode ^ (tmp%2);
            vec[arr[pointer+1]].push_back(pointer+1);

            pointer += 2;
        }
        else{
            int tmp = use_machine(vector<int> {need, vec[mode][0], pointer, vec[mode][1], pointer+1, vec[mode][2]});

            arr[need] = mode ^ (tmp % 2);
            vec[arr[need]].push_back(need);

            arr[need-1] = !arr[need];
            vec[arr[need-1]].push_back(need-1);
            need = 0;

            if(tmp/2 == 0){
                arr[pointer] = arr[pointer+1] = mode;
                vec[mode].push_back(pointer);
                vec[mode].push_back(pointer+1);
            }
            else if(tmp/2 == 2){
                arr[pointer] = arr[pointer+1] = !mode;
                vec[!mode].push_back(pointer);
                vec[!mode].push_back(pointer+1);
            }
            else{
                need = pointer+1;
            }
            pointer += 2;
        }
    }

    while(pointer < n){
        int mode = (vec[0].size() >= vec[1].size() ? 0 : 1);
        vector<int> queryVec (1, pointer++);
        queryVec.push_back(vec[mode][0]);

        for(int i=1; i<(int)vec[mode].size() && pointer<n; i++){
            queryVec.push_back(pointer++);
            queryVec.push_back(vec[mode][i]);
        }

        int ret = use_machine(queryVec);
        int spnt = queryVec[0];

        arr[spnt] = mode ^ (ret % 2);
        vec[arr[spnt]].push_back(spnt);
        ret /= 2;

        for(int j=spnt+1; j<pointer; j++){
            if(j <= spnt+ret) arr[j] = !mode;
            else arr[j] = mode;
        }
    }

    for(int i=0; i<n; i++){
        if(arr[i] == 0) ans++;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 2 ms 312 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 9 ms 328 KB Output is correct
9 Correct 7 ms 328 KB Output is correct
10 Correct 8 ms 328 KB Output is correct
11 Correct 8 ms 328 KB Output is correct
12 Correct 8 ms 364 KB Output is correct
13 Correct 7 ms 312 KB Output is correct
14 Correct 6 ms 320 KB Output is correct
15 Correct 8 ms 300 KB Output is correct
16 Correct 10 ms 324 KB Output is correct
17 Correct 5 ms 328 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 7 ms 328 KB Output is correct
20 Correct 7 ms 328 KB Output is correct
21 Correct 9 ms 328 KB Output is correct
22 Correct 8 ms 348 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 5 ms 328 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 8 ms 332 KB Output is correct
27 Correct 9 ms 340 KB Output is correct
28 Correct 8 ms 352 KB Output is correct
29 Correct 8 ms 328 KB Output is correct
30 Correct 10 ms 320 KB Output is correct
31 Correct 9 ms 328 KB Output is correct
32 Correct 7 ms 372 KB Output is correct
33 Correct 9 ms 344 KB Output is correct
34 Correct 9 ms 312 KB Output is correct
35 Correct 7 ms 364 KB Output is correct
36 Correct 11 ms 376 KB Output is correct
37 Correct 8 ms 328 KB Output is correct
38 Correct 9 ms 312 KB Output is correct
39 Correct 9 ms 328 KB Output is correct
40 Correct 8 ms 364 KB Output is correct
41 Correct 8 ms 328 KB Output is correct
42 Correct 9 ms 328 KB Output is correct
43 Correct 8 ms 328 KB Output is correct
44 Correct 7 ms 352 KB Output is correct
45 Correct 8 ms 376 KB Output is correct
46 Correct 8 ms 380 KB Output is correct
47 Correct 9 ms 364 KB Output is correct
48 Correct 9 ms 348 KB Output is correct
49 Correct 9 ms 356 KB Output is correct
50 Correct 9 ms 328 KB Output is correct
51 Correct 10 ms 316 KB Output is correct
52 Correct 8 ms 364 KB Output is correct
53 Correct 9 ms 364 KB Output is correct
54 Correct 8 ms 328 KB Output is correct
55 Correct 10 ms 356 KB Output is correct
56 Correct 8 ms 328 KB Output is correct
57 Correct 9 ms 360 KB Output is correct
58 Correct 9 ms 328 KB Output is correct
59 Correct 9 ms 328 KB Output is correct
60 Correct 8 ms 328 KB Output is correct
61 Correct 10 ms 328 KB Output is correct
62 Correct 1 ms 200 KB Output is correct
63 Correct 1 ms 200 KB Output is correct
64 Correct 1 ms 200 KB Output is correct
65 Correct 1 ms 200 KB Output is correct
66 Correct 1 ms 200 KB Output is correct
67 Correct 1 ms 200 KB Output is correct
68 Correct 1 ms 200 KB Output is correct
69 Correct 1 ms 200 KB Output is correct
70 Correct 1 ms 200 KB Output is correct
71 Correct 1 ms 200 KB Output is correct
72 Correct 1 ms 200 KB Output is correct
73 Correct 1 ms 200 KB Output is correct
74 Correct 1 ms 200 KB Output is correct
75 Correct 1 ms 200 KB Output is correct
76 Correct 1 ms 200 KB Output is correct
77 Correct 1 ms 200 KB Output is correct
78 Correct 1 ms 200 KB Output is correct
79 Correct 1 ms 200 KB Output is correct
80 Correct 1 ms 200 KB Output is correct
81 Correct 1 ms 200 KB Output is correct
82 Correct 1 ms 200 KB Output is correct
83 Correct 1 ms 200 KB Output is correct
84 Correct 1 ms 200 KB Output is correct
85 Correct 1 ms 200 KB Output is correct
86 Correct 1 ms 200 KB Output is correct
87 Correct 1 ms 200 KB Output is correct
88 Correct 1 ms 200 KB Output is correct
89 Correct 1 ms 200 KB Output is correct
90 Correct 1 ms 200 KB Output is correct
91 Correct 1 ms 200 KB Output is correct