Submission #544831

#TimeUsernameProblemLanguageResultExecution timeMemory
544831LoboCounting Mushrooms (IOI20_mushrooms)C++17
73.38 / 100
9 ms316 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 2e4 + 10;


// int s[maxn];
// int use_machine(vector<int> x) {
//     const int xs = x.size();
    
//     int diffs = 0;
//     for (int i = 1; i < xs; i++)
//         diffs += int(s[x[i]] != s[x[i-1]]);
//     return diffs;
// }

int a[maxn];

int count_mushrooms(int n) {
    int B = 124;

    vector<int> va, vb;
    a[0] = 1;
    va.pb(0);
    for(int i = 1; i < n; i++) {
        if(i == n-1 || n <= 226) {
            vector<int> vqr; vqr.pb(0); vqr.pb(i);
            if(use_machine(vqr) == 0) {
                va.pb(i);
                a[i] = 1;
            }
            else {
                vb.pb(i);
                a[i] = 1;
            }
            continue;
        }

        bool ok = true;
        if(i == n-2) {
            ok = false;
            i--;
        }
        vector<int> vqr;
        vqr.pb(0);
        vqr.pb(i);
        vqr.pb(i+1);
        vqr.pb(i+2);

        int qr = use_machine(vqr);
        qr = ((int) vqr.size()) -1 - qr;

        if(qr == 3) {
            if(ok) va.pb(i);
            va.pb(i+1);
            va.pb(i+2);
            a[i] = 1;
            a[i+1] = 1;
            a[i+2] = 1;
        }
        else if(qr == 0) {
            if(ok) vb.pb(i);
            va.pb(i+1);
            vb.pb(i+2);
            a[i] = 1;
            a[i+1] = 1;
            a[i+2] = 1;
        }
        else if(qr == 2) {
            vb.pb(i+2);
            a[i+2] = 1;

            vector<int> vqr1;
            vqr1.pb(i);
            vqr1.pb(0);
            vqr1.pb(i+1);

            int qr1 = use_machine(vqr1);
            qr1 = ((int) vqr1.size()) -1 - qr1;
            if(qr1 == 0) {
                if(ok) vb.pb(i);
                vb.pb(i+1);
                a[i] = 1;
                a[i+1] = 1;
            }
            else if(qr1 == 1) {
                if(ok) va.pb(i);
                vb.pb(i+1);
                a[i] = 1;
                a[i+1] = 1;
            }
            else {
                if(ok) va.pb(i);
                va.pb(i+1);
                a[i] = 1;
                a[i+1] = 1;
            }
        }
        else if(qr == 1) {
            va.pb(i+2);
            a[i+2] = 1;
            vector<int> vqr1;
            vqr1.pb(0);
            vqr1.pb(i);
            vqr1.pb(i+2);
            vqr1.pb(i+1);

            int qr1 = use_machine(vqr1);
            qr1 = ((int) vqr1.size()) -1 - qr1;

            if(qr1 == 0) {
                if(ok) vb.pb(i);
                vb.pb(i+1);
                a[i] = 1;
                a[i+1] = 1;
            }
            else if(qr1 == 1) {
                if(ok) vb.pb(i);
                va.pb(i+1);
                a[i] = 1;
                a[i+1] = 1;
            }
            else if(qr1 == 2) {
                if(ok) va.pb(i);
                vb.pb(i+1);
                a[i] = 1;
                a[i+1] = 1;
            }
        }

        i = i+2;
        if(va.size() >= B || vb.size() >= B) {
            break;
        }
    }

    int ans = va.size();

    if(va.size() >= B) {
        int i = 1;
        while(i != n) {
            int j = 0;
            vector<int> vqr;
            while(vqr.size() != 2*B-2 && i != n) {
                if(a[i] != 0) {
                    i++;
                    continue;
                }
                vqr.pb(va[j++]);
                vqr.pb(i++);
            }
            if(vqr.size() == 0) continue;
            vqr.pb(va[j]);
            int qr = use_machine(vqr);
            qr = ((int) vqr.size()) -1 - qr;
            ans+= qr/2;
        }
    }
    else {
        int i = 1;
        while(i != n) {
            int j = 0;
            vector<int> vqr;
            while(vqr.size() != 2*B-2 && i != n) {
                if(a[i] != 0) {
                    i++;
                    continue;
                }
                vqr.pb(vb[j++]);
                vqr.pb(i++);
            }
            if(vqr.size() == 0) continue;
            vqr.pb(vb[j]);
            int qr = use_machine(vqr);
            qr = ((int) vqr.size()) -1 - qr;
            ans+= ((int) vqr.size())/2 - qr/2;
        }
    }

    return ans;


}


// int32_t main() {
//     ios::sync_with_stdio(false); cin.tie(0);

//     freopen("in.in", "r", stdin);
//     // freopen("out.out", "w", stdout);
    
//     int n;
//     cin >> n;
//     for(int i = 0; i < n; i++) {
//         int x; cin >> x;
//         s[i] = x;
//     }

//     cout << count_mushrooms(n) << endl;

// }

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:144:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  144 |         if(va.size() >= B || vb.size() >= B) {
      |            ~~~~~~~~~~^~~~
mushrooms.cpp:144:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  144 |         if(va.size() >= B || vb.size() >= B) {
      |                              ~~~~~~~~~~^~~~
mushrooms.cpp:151:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  151 |     if(va.size() >= B) {
      |        ~~~~~~~~~~^~~~
mushrooms.cpp:156:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  156 |             while(vqr.size() != 2*B-2 && i != n) {
      |                   ~~~~~~~~~~~^~~~~~~~
mushrooms.cpp:176:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  176 |             while(vqr.size() != 2*B-2 && i != n) {
      |                   ~~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...