Submission #624660

# Submission time Handle Problem Language Result Execution time Memory
624660 2022-08-08T15:05:12 Z Awerar Counting Mushrooms (IOI20_mushrooms) C++14
92.2449 / 100
113 ms 764 KB
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17

#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif

#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)

#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)

#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)

auto Start = chrono::high_resolution_clock::now();

inline void fast()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

int use_machine(vector<int> x);

int submit_query(vector<int> x) {
    cerr << "x = {";
    for(int v : x) cerr << v << ", ";
    cerr << "}\n";

    return use_machine(x);
}

vector<int> apos = { 0 }, bpos;
int num_checked = 1, a_count = 1;
int n;

int get_num_to_discover() {
    return (apos.size() < 2 && bpos.size() < 2) || n - num_checked < 2 ? 1 : 2;
}

int get_num_to_count() {
    return min(n - num_checked, (int)max(apos.size(), bpos.size()));
}

void discover() {
    if(get_num_to_discover() == 1) {
        cerr << "Discover 1" << endl;

        int res = submit_query({ 0, num_checked });
        
        (res == 0 ? apos : bpos).push_back(num_checked);
        if(res == 0) a_count++;

        num_checked++;
    } else {
        cerr << "Discover 2" << endl;

        bool a_used = apos.size() > bpos.size();
        vector<int>& arr = a_used ? apos : bpos;

        int res = submit_query({ arr[0], num_checked, arr[1], num_checked + 1 });

        pair<bool, bool> same;
        if(res == 0) same = { true, true };
        else if(res == 1) same = { true, false };
        else if(res == 2) same = { false, true };
        else same = { false, false };

        if(a_used ^ same.first) {
            bpos.push_back(num_checked);
        } else {
            apos.push_back(num_checked);
            a_count++;
        }
        
        if(a_used ^ same.second) {
            bpos.push_back(num_checked + 1);
        } else {
            apos.push_back(num_checked + 1);
            a_count++;
        }

        num_checked += 2;
    }
}

void count() {
    cerr << "Counting" << endl;
    
    bool a_used = apos.size() > bpos.size();
    vector<int>& arr = a_used ? apos : bpos;

    int num_query = get_num_to_count();
    vector<int> q;
    for(int i = 0; i < num_query; i++) {
        q.push_back(arr[i]);
        q.push_back(num_checked + i);
    }

    int res = submit_query(q);
    int num_same = num_query - ceildiv(res, 2);

    num_checked += num_query;

    if(a_used) a_count += num_same;
    else a_count += num_query - num_same;

    if((res % 2 == 1) ^ a_used) apos.push_back(num_checked - 1);
    else bpos.push_back(num_checked - 1);
}

int count_mushrooms(int N) {
    n = N;

    int k = 69;
    while(num_checked < n) {
        int end_now = ceildiv((n - num_checked), max(apos.size(), bpos.size()));
        
        //int worst_a = apos.size(), worst_b = bpos.size();
        int num_to_discover = get_num_to_discover();
        //for(int i = 0; i < num_to_discover; i++) (worst_a < worst_b ? worst_a : worst_b)++;

        int end_next = 1 + ceildiv((n - num_checked - num_to_discover), (max(apos.size(), bpos.size()) + 1));

        k--;
        if(k == 0) break;
        if(end_now < end_next) break;

        cerr << "Checked: " << num_checked << endl;
        discover();
    }

    while(num_checked < n) {
        count();
    }

    return a_count;
}

Compilation message

mushrooms.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   18 | #pragma GCC optimization ("O3")
      | 
mushrooms.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   19 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 12 ms 336 KB Output is correct
7 Correct 101 ms 620 KB Output is correct
8 Correct 105 ms 520 KB Output is correct
9 Correct 100 ms 516 KB Output is correct
10 Correct 100 ms 564 KB Output is correct
11 Partially correct 112 ms 568 KB Output is partially correct
12 Correct 102 ms 484 KB Output is correct
13 Correct 101 ms 532 KB Output is correct
14 Correct 56 ms 336 KB Output is correct
15 Partially correct 105 ms 676 KB Output is partially correct
16 Partially correct 105 ms 572 KB Output is partially correct
17 Correct 54 ms 516 KB Output is correct
18 Correct 103 ms 472 KB Output is correct
19 Partially correct 105 ms 764 KB Output is partially correct
20 Correct 99 ms 548 KB Output is correct
21 Correct 99 ms 572 KB Output is correct
22 Partially correct 103 ms 576 KB Output is partially correct
23 Correct 103 ms 456 KB Output is correct
24 Correct 56 ms 432 KB Output is correct
25 Partially correct 102 ms 568 KB Output is partially correct
26 Partially correct 109 ms 476 KB Output is partially correct
27 Partially correct 101 ms 480 KB Output is partially correct
28 Partially correct 105 ms 568 KB Output is partially correct
29 Partially correct 104 ms 448 KB Output is partially correct
30 Partially correct 105 ms 552 KB Output is partially correct
31 Partially correct 109 ms 668 KB Output is partially correct
32 Partially correct 106 ms 556 KB Output is partially correct
33 Partially correct 105 ms 448 KB Output is partially correct
34 Partially correct 102 ms 568 KB Output is partially correct
35 Partially correct 103 ms 572 KB Output is partially correct
36 Partially correct 106 ms 572 KB Output is partially correct
37 Partially correct 106 ms 564 KB Output is partially correct
38 Partially correct 99 ms 568 KB Output is partially correct
39 Partially correct 108 ms 544 KB Output is partially correct
40 Partially correct 105 ms 468 KB Output is partially correct
41 Partially correct 110 ms 760 KB Output is partially correct
42 Partially correct 108 ms 500 KB Output is partially correct
43 Partially correct 98 ms 572 KB Output is partially correct
44 Partially correct 108 ms 468 KB Output is partially correct
45 Partially correct 104 ms 572 KB Output is partially correct
46 Partially correct 109 ms 488 KB Output is partially correct
47 Partially correct 108 ms 568 KB Output is partially correct
48 Partially correct 104 ms 564 KB Output is partially correct
49 Partially correct 106 ms 536 KB Output is partially correct
50 Partially correct 105 ms 676 KB Output is partially correct
51 Partially correct 104 ms 564 KB Output is partially correct
52 Partially correct 105 ms 464 KB Output is partially correct
53 Partially correct 109 ms 688 KB Output is partially correct
54 Partially correct 106 ms 468 KB Output is partially correct
55 Partially correct 104 ms 480 KB Output is partially correct
56 Partially correct 105 ms 564 KB Output is partially correct
57 Partially correct 102 ms 576 KB Output is partially correct
58 Partially correct 102 ms 568 KB Output is partially correct
59 Partially correct 113 ms 656 KB Output is partially correct
60 Partially correct 104 ms 456 KB Output is partially correct
61 Partially correct 101 ms 544 KB Output is partially correct
62 Correct 1 ms 208 KB Output is correct
63 Correct 0 ms 208 KB Output is correct
64 Correct 0 ms 208 KB Output is correct
65 Correct 1 ms 208 KB Output is correct
66 Correct 0 ms 208 KB Output is correct
67 Correct 1 ms 208 KB Output is correct
68 Correct 1 ms 208 KB Output is correct
69 Correct 1 ms 208 KB Output is correct
70 Correct 0 ms 208 KB Output is correct
71 Correct 0 ms 208 KB Output is correct
72 Correct 0 ms 208 KB Output is correct
73 Correct 1 ms 208 KB Output is correct
74 Correct 0 ms 248 KB Output is correct
75 Correct 1 ms 208 KB Output is correct
76 Correct 1 ms 208 KB Output is correct
77 Correct 0 ms 208 KB Output is correct
78 Correct 1 ms 208 KB Output is correct
79 Correct 0 ms 208 KB Output is correct
80 Correct 0 ms 208 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 0 ms 208 KB Output is correct
83 Correct 1 ms 208 KB Output is correct
84 Correct 0 ms 208 KB Output is correct
85 Correct 1 ms 208 KB Output is correct
86 Correct 1 ms 208 KB Output is correct
87 Correct 1 ms 288 KB Output is correct
88 Correct 0 ms 208 KB Output is correct
89 Correct 0 ms 208 KB Output is correct
90 Correct 1 ms 208 KB Output is correct
91 Correct 0 ms 208 KB Output is correct