Submission #484998

# Submission time Handle Problem Language Result Execution time Memory
484998 2021-11-05T21:12:24 Z AmirElarbi Counting Mushrooms (IOI20_mushrooms) C++14
100 / 100
9 ms 348 KB
#include "mushrooms.h"
 
#include <bits/stdc++.h>
 
 #define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define fi first
#define se second
#define INF 1e7
#define eps 1e-18
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9+7;
const int nax = 2000005;

int count_mushrooms(int n) {
    int X = 200;
    vi typ[2];
    typ[0].pb(0);
    if(n < 300){
        int cnt = 1;
        for(int i = 1;i<n;i++){
            vector<int> a;
            a.push_back(0);
            a.push_back(i);
            int x = use_machine(a);
            if(x == 0)cnt++;
        }
        return cnt;
    }
    for(int i = 1; i <= 2; i++){
        typ[use_machine({0,i})].pb(i);
    }
    bool B = false;
    if(typ[1].size() == 2)
        B = true;
    int res = 0;
    res = use_machine({typ[B][0],3,typ[B][1], 4});
    if(res == 0){
        typ[B].pb(3);
        typ[B].pb(4);
    } else if(res == 1){
        typ[B].pb(3);
        typ[B^1].pb(4);
    } else if(res == 2){
        typ[B^1].pb(3);
        typ[B].pb(4);
    } else {
        typ[B^1].pb(3);
        typ[B^1].pb(4);
    }
    B = false;
    if(typ[1].size() >= 3)
        B = true;
    for (int i = 5; i < X; i+=5)
    {
        int res = use_machine({typ[B][0], i, typ[B][1],i+1, typ[B][2], i+2});
        if(res%2==1)
            typ[1-B].pb(i+2);
        else typ[B].pb(i+2);
        res -= res%2;
        if(res%4==0){
            if(res == 4){
                typ[B^1].pb(i);
                typ[B^1].pb(i+1);
            } else if(res == 0){
                typ[B].pb(i);
                typ[B].pb(i+1);
            }
            res = use_machine({typ[B][0], i+3, typ[B][1],i+4});
            if(res == 0){
                typ[B].pb(i+3);
                typ[B].pb(i+4);
            } else if(res == 1){
                typ[B].pb(i+3);
                typ[B^1].pb(i+4);
            } else if(res == 2){
                typ[B^1].pb(i+3);
                typ[B].pb(i+4);
            } else {
                typ[B^1].pb(i+3);
                typ[B^1].pb(i+4);
            }
        } else {
            if(min(typ[0].size(), typ[1].size())>=2){
                res = use_machine({typ[B^1][0], i, typ[B^1][1], typ[B][0],i+1, typ[B][1], i+3 ,typ[B][2], i+4});
                if(res%2==0){
                    typ[1-B].pb(i+4);
                    res--;
                }
                else typ[B].pb(i+4);
                if(res>=4){
                    typ[B].pb(i);
                    typ[1-B].pb(i+1);
                    if(res == 5) typ[B].pb(i+3);
                    else typ[1-B].pb(i+3);
                } else {
                    typ[1-B].pb(i);
                    typ[B].pb(i+1);
                    if(res == 1) typ[B].pb(i+3);
                    else typ[1-B].pb(i+3);
                }
            } else {
                res = use_machine({0,i});
                typ[res].pb(i);
                typ[1-res].pb(i+1);
                res = use_machine({typ[B][0], i+3, typ[B][1],i+4});
                if(res == 0){
                    typ[B].pb(i+3);
                    typ[B].pb(i+4);
                } else if(res == 1){
                    typ[B].pb(i+3);
                    typ[B^1].pb(i+4);
                } else if(res == 2){
                    typ[B^1].pb(i+3);
                    typ[B].pb(i+4);
                } else {
                    typ[B^1].pb(i+3);
                    typ[B^1].pb(i+4);
                }
            }
        }
    }
    int cnt = typ[0].size();
    #define sz(x) (int)x.size()
    {
        int i = X;
        while(i<n){
             if(sz(typ[0]) >= sz(typ[1])){
            vector<int> a;
            for(int j : typ[0]){
                a.pb(j);
                a.pb(i);
                i++;
                if(i == n)break;
            }
            int x = use_machine(a);
            cnt += (int)(a.size()/2) - (x+1)/2;
            if(x%2){
                typ[1].pb(a.back());
            }
            else typ[0].pb(a.back());
            }
             else {
                vector<int> b;
            for(int j : typ[1]){
                b.pb(j);
                b.pb(i);
                i++;
                if(i == n)break;
            }
            int x = use_machine(b);
            cnt += (x+1)/2;
             if(x%2){
                typ[0].pb(b.back());
            }
            else typ[1].pb(b.back());
             }
 
        }
    }
    return cnt;
 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 3 ms 200 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 5 ms 308 KB Output is correct
8 Correct 5 ms 312 KB Output is correct
9 Correct 7 ms 200 KB Output is correct
10 Correct 6 ms 200 KB Output is correct
11 Correct 7 ms 320 KB Output is correct
12 Correct 6 ms 300 KB Output is correct
13 Correct 7 ms 308 KB Output is correct
14 Correct 4 ms 200 KB Output is correct
15 Correct 6 ms 200 KB Output is correct
16 Correct 5 ms 200 KB Output is correct
17 Correct 4 ms 200 KB Output is correct
18 Correct 6 ms 312 KB Output is correct
19 Correct 6 ms 348 KB Output is correct
20 Correct 6 ms 200 KB Output is correct
21 Correct 6 ms 200 KB Output is correct
22 Correct 6 ms 200 KB Output is correct
23 Correct 6 ms 200 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 6 ms 200 KB Output is correct
26 Correct 6 ms 200 KB Output is correct
27 Correct 6 ms 200 KB Output is correct
28 Correct 6 ms 312 KB Output is correct
29 Correct 9 ms 296 KB Output is correct
30 Correct 6 ms 204 KB Output is correct
31 Correct 5 ms 316 KB Output is correct
32 Correct 6 ms 200 KB Output is correct
33 Correct 7 ms 316 KB Output is correct
34 Correct 6 ms 200 KB Output is correct
35 Correct 6 ms 308 KB Output is correct
36 Correct 5 ms 312 KB Output is correct
37 Correct 7 ms 308 KB Output is correct
38 Correct 5 ms 200 KB Output is correct
39 Correct 6 ms 200 KB Output is correct
40 Correct 6 ms 304 KB Output is correct
41 Correct 6 ms 200 KB Output is correct
42 Correct 7 ms 200 KB Output is correct
43 Correct 6 ms 200 KB Output is correct
44 Correct 6 ms 200 KB Output is correct
45 Correct 5 ms 200 KB Output is correct
46 Correct 7 ms 200 KB Output is correct
47 Correct 5 ms 316 KB Output is correct
48 Correct 5 ms 316 KB Output is correct
49 Correct 6 ms 200 KB Output is correct
50 Correct 6 ms 200 KB Output is correct
51 Correct 6 ms 312 KB Output is correct
52 Correct 8 ms 304 KB Output is correct
53 Correct 9 ms 200 KB Output is correct
54 Correct 7 ms 308 KB Output is correct
55 Correct 6 ms 316 KB Output is correct
56 Correct 6 ms 200 KB Output is correct
57 Correct 6 ms 300 KB Output is correct
58 Correct 6 ms 320 KB Output is correct
59 Correct 6 ms 200 KB Output is correct
60 Correct 6 ms 308 KB Output is correct
61 Correct 8 ms 200 KB Output is correct
62 Correct 0 ms 200 KB Output is correct
63 Correct 0 ms 200 KB Output is correct
64 Correct 0 ms 200 KB Output is correct
65 Correct 0 ms 200 KB Output is correct
66 Correct 0 ms 200 KB Output is correct
67 Correct 1 ms 200 KB Output is correct
68 Correct 0 ms 200 KB Output is correct
69 Correct 1 ms 200 KB Output is correct
70 Correct 0 ms 200 KB Output is correct
71 Correct 0 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 0 ms 200 KB Output is correct
75 Correct 0 ms 200 KB Output is correct
76 Correct 0 ms 200 KB Output is correct
77 Correct 0 ms 200 KB Output is correct
78 Correct 0 ms 200 KB Output is correct
79 Correct 0 ms 200 KB Output is correct
80 Correct 0 ms 200 KB Output is correct
81 Correct 0 ms 200 KB Output is correct
82 Correct 0 ms 200 KB Output is correct
83 Correct 0 ms 200 KB Output is correct
84 Correct 0 ms 200 KB Output is correct
85 Correct 0 ms 200 KB Output is correct
86 Correct 0 ms 200 KB Output is correct
87 Correct 0 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 0 ms 200 KB Output is correct
91 Correct 0 ms 200 KB Output is correct