제출 #759983

#제출 시각아이디문제언어결과실행 시간메모리
759983raysh07버섯 세기 (IOI20_mushrooms)C++17
92.62 / 100
7 ms336 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 = 170;
    int moves = 0;
    
    while (p < n){
        if (p != (n - 1) && (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...