Submission #760093

#TimeUsernameProblemLanguageResultExecution timeMemory
760093raysh07Counting Mushrooms (IOI20_mushrooms)C++17
0 / 100
6 ms332 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

// const int N = 101;
// int ac[N];

// int use_machine(vector <int> a){
//     int ans = 0;
    
//     for (int i = 1; i < a.size(); i++){
//         ans += ac[a[i]] != ac[a[i - 1]];
//     }
    
//     return ans;
// }
 
int count_mushrooms(int n) {
    vector <int> a, b;
    a.push_back(0);
    int p = 1;
    int ans = 0;
    const int C = 80;
    int moves = 0;
    
    while (p < n){
        if (p != (n - 1) && p != (n - 2) && max(a.size(), b.size()) <= C && max(a.size(), b.size()) >= 3){
            if (a.size() >= 3){
                int c = use_machine({p, a[0], p + 1, a[1], p + 2, a[2]});
                if (c & 1) b.push_back(p), c--;
                else a.push_back(p);
                
                if (c == 0) {
                    a.push_back(p + 1);
                    a.push_back(p + 2);
                    p += 3;
                } else if (c == 4){
                    b.push_back(p + 1);
                    b.push_back(p + 2);
                    p += 3;
                } else {
                    assert(c == 2);
                    if (b.size() >= 2 && p + 4 < n){
                        c = use_machine({b[0], p + 1, b[1], a[0], p + 2, a[1], p + 3, a[2], p + 4});
                        c--;
                        if (c >= 4) {
                            a.push_back(p + 1);
                            b.push_back(p + 2);
                            c -= 4;
                        } else {
                            a.push_back(p + 2);
                            b.push_back(p + 1);
                        }
                        
                        if (c & 1) b.push_back(p + 4), c--;
                        else a.push_back(p + 4);
                        
                        if (c == 2) b.push_back(p + 3);
                        else a.push_back(p + 3);
                        
                        p += 5;
                    } else {
                        c = use_machine({p + 1, a[0], p + 2, a[1]});
                        if (c & 1) b.push_back(p + 1);
                        else a.push_back(p + 1);
                        
                        if (c >= 2) b.push_back(p + 2);
                        else a.push_back(p + 2);
                        p += 3;
                    }
                }
            } 
            else {
                int c = use_machine({p, b[0], p + 1, b[1], p + 2, b[2]});
                if (c & 1) a.push_back(p), c--;
                else b.push_back(p);
                
                if (c == 0){
                    b.push_back(p + 1);
                    b.push_back(p + 2);
                    p += 3;
                } else if (c == 4){
                    a.push_back(p + 1);
                    a.push_back(p + 2);
                    p += 3;
                } else {
                    if (a.size() >= 2 && p + 4 < n){
                        c = use_machine({a[0], p + 1, a[1], b[0], p + 2, b[1], p + 3, b[2], p + 4});
                        c--;
                        
                        if (c >= 4) {
                            b.push_back(p + 1);
                            a.push_back(p + 2);
                            c -= 4;
                        } else {
                            a.push_back(p + 1);
                            b.push_back(p + 2);
                        }
                        
                        if (c & 1) a.push_back(p + 4), c--;
                        else b.push_back(p + 4);
                        
                        if (c == 2) a.push_back(p + 3);
                        else b.push_back(p + 3);
                        
                        p += 5;
                    } else {
                        c = use_machine({p + 1, b[0], p + 2, b[1]});
                        if (c & 1) a.push_back(p + 1), c--;
                        else b.push_back(c + 1);
                        
                        if (c == 2) a.push_back(p + 2);
                        else b.push_back(p + 2);
                        
                        p += 3;
                    }
                }
            }
            continue;
        }
        if (p != (n - 1) && max(a.size(), b.size()) <= C && max(a.size(), b.size()) >= 2){
            if (a.size() >= 2) {
                int c = use_machine({a[0], p, a[1], p + 1});
                moves++;
                if (c & 1) b.push_back(p + 1);
                else a.push_back(p + 1);
                if (c >= 2) b.push_back(p);
                else a.push_back(p);
            } else {
                int c = use_machine({b[0], p, b[1], p + 1});
                moves++;
                if (c & 1) a.push_back(p + 1);
                else b.push_back(p + 1);
                if (c >= 2) a.push_back(p);
                else b.push_back(p);
            }
            
            p += 2;
            continue;
        }
        // cout << "PRINTING " << p << " ";
        // for (auto x : a) cout << x << " ";
        // cout << "\n";
        if (a.size() > b.size()){
            int g = a.size();
            g = min(g, n - p);
            
            vector <int> m;
            for (int i = 0; i < g; i++){
                m.push_back(p + i);
                m.push_back(a[i]);
            }
            
            int c = use_machine(m);
            if (c & 1) b.push_back(p), c--;
            else a.push_back(p);
            moves++;
            
          //  cout << g << " " << c/2 << "\n";
            ans += g - 1 - (c/2);
            p += g;
        } else {
            int g = b.size();
            g = min(g, n - p);
            
            vector <int> m;
            for (int i = 0; i < g; i++){
                m.push_back(p + i);
                m.push_back(b[i]);
            }
            
            int c = use_machine(m);
            if (c & 1) a.push_back(p), c--;
            else b.push_back(p);
            moves++;
            
            ans += c/2;
            p += g;
        }
    }
    
    return ans + a.size();
}

// int main(){
//     int n; cin >> n;
//     for (int i = 0; i < n; i++) cin >> ac[i];
    
//     cout << count_mushrooms(n) << "\n";
//     return 0;
// }
#Verdict Execution timeMemoryGrader output
Fetching results...