Submission #303598

# Submission time Handle Problem Language Result Execution time Memory
303598 2020-09-20T13:11:49 Z jtnydv25 Counting Mushrooms (IOI20_mushrooms) C++17
82.7839 / 100
937 ms 636 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
const int M = 8;
 
int val[200005];
struct node{
	vector<int> states;
	node* res[M];
	vector<int> ask;
	int maxQueries;
	node(){
		for(int i = 0; i < M; i++) res[i] = NULL;
		maxQueries = 0;
	}
	void compute(){
		int n = states.size();
		if(n == 1) return;
		maxQueries = 1;
		int mn = 1 << 20;
		for(int mask = 1; mask < (1 << M); mask++){
			vector<int> perm;
            for(int j = 0; j < M; j++) if(mask >> j & 1) perm.push_back(j);
            if(((int)perm.size()) == 1) continue;
            do{
                vector<int> num(M);
                for(int s : states){
                    int r = 0;
                    for(int j = 0; j + 1 < (int)perm.size(); j++) r += (s >> perm[j] & 1) != (s >> perm[j + 1] & 1);
                    num[r]++;
                }
                int V = *max_element(num.begin(), num.end());
                if(V < mn){
                    mn = V;
                    ask = perm;
                }
            }while(next_permutation(perm.begin(), perm.end()));
		}
        vector<int> perm = ask;
 
		vector<vector<int>> childStates(M);
		
        for(int s : states){
            int r = 0;
            for(int j = 0; j + 1 < (int)perm.size(); j++) r += (s >> perm[j] & 1) != (s >> perm[j + 1] & 1);
            childStates[r].push_back(s);
        }
		for(int i = 0; i < M; i++){
			if(!childStates[i].empty()){
				res[i] = new node();
				res[i]->states = childStates[i];
				res[i]->compute();
				maxQueries = max(maxQueries, res[i]->maxQueries + 1);
			}
		}
	}
    void get(vector<int> positions){
        if((int)states.size() == 1){
            for(int i = 0; i < M; i++) val[positions[i]] = states[0] >> i & 1;
            return;
        }
 
        vector<int> x;
        for(int i : ask) x.push_back(positions[i]);
        res[use_machine(x)]->get(positions);
    }
};
 
int get(int pos){
    return val[pos] = use_machine({0, pos});
}
 
struct decision_tree{
	node * root;
	decision_tree(){
		root = new node();
		for(int i = 0; i < (1 << M); i+=2) root->states.push_back(i);
		root->compute();
	}
    void get(vector<int> positions){
        root->get(positions);
    }
};
 
const int K = 350;
 
int count_mushrooms(int N) {
	decision_tree DT;
    int n = min(N, K);
    // int n = N;
    // for(int j = 1; j < N; j++) get(j);
    for(int i = 1; i < n; i += M - 1){
        int st = i, en = i + M - 2;
        if(en < n){
            vector<int> positions = {0};
            for(int j = st; j <= en; j++) positions.push_back(j);
            DT.get(positions);
        } else{
            for(int j = st; j < n; j++) get(j);
        }
    }
 
    int curr = n - accumulate(val, val + n, 0);
    if(n == N) return curr;
	vector<vector<int>> where(2);
    for(int i = 0; i < n; i++) where[val[i]].push_back(i);
    int id = (int)where[1].size() > (int) where[0].size();
    int R = where[id].size() - 1;
    for(int i = n; i < N; i += R){
        int st = i, en = min(N - 1, i + R - 1);
        vector<int> positions = {where[id][0]};
        for(int j = 0; j <= en - st; j++){
            positions.push_back(st + j);
            positions.push_back(where[id][j + 1]);
        }
        int V = use_machine(positions);
        assert(V % 2 == 0);
        V /= 2;
        if(id == 1) curr += V;
        else curr += en - st + 1 - V;
    }
    return curr;
}
# Verdict Execution time Memory Grader output
1 Correct 595 ms 504 KB Output is correct
2 Correct 603 ms 380 KB Output is correct
3 Correct 600 ms 388 KB Output is correct
4 Correct 615 ms 388 KB Output is correct
5 Correct 586 ms 380 KB Output is correct
6 Correct 602 ms 504 KB Output is correct
7 Correct 668 ms 508 KB Output is correct
8 Correct 640 ms 492 KB Output is correct
9 Correct 587 ms 496 KB Output is correct
10 Partially correct 618 ms 384 KB Output is partially correct
11 Partially correct 725 ms 512 KB Output is partially correct
12 Partially correct 592 ms 376 KB Output is partially correct
13 Correct 630 ms 408 KB Output is correct
14 Correct 600 ms 380 KB Output is correct
15 Partially correct 637 ms 376 KB Output is partially correct
16 Partially correct 642 ms 496 KB Output is partially correct
17 Correct 592 ms 376 KB Output is correct
18 Correct 604 ms 504 KB Output is correct
19 Partially correct 653 ms 632 KB Output is partially correct
20 Partially correct 624 ms 504 KB Output is partially correct
21 Partially correct 637 ms 376 KB Output is partially correct
22 Partially correct 591 ms 368 KB Output is partially correct
23 Correct 621 ms 636 KB Output is correct
24 Correct 603 ms 400 KB Output is correct
25 Partially correct 590 ms 500 KB Output is partially correct
26 Partially correct 611 ms 496 KB Output is partially correct
27 Partially correct 599 ms 368 KB Output is partially correct
28 Partially correct 632 ms 504 KB Output is partially correct
29 Partially correct 585 ms 376 KB Output is partially correct
30 Partially correct 678 ms 392 KB Output is partially correct
31 Partially correct 605 ms 408 KB Output is partially correct
32 Partially correct 679 ms 376 KB Output is partially correct
33 Partially correct 616 ms 380 KB Output is partially correct
34 Partially correct 599 ms 368 KB Output is partially correct
35 Partially correct 631 ms 412 KB Output is partially correct
36 Partially correct 612 ms 408 KB Output is partially correct
37 Partially correct 608 ms 380 KB Output is partially correct
38 Partially correct 592 ms 368 KB Output is partially correct
39 Partially correct 591 ms 376 KB Output is partially correct
40 Partially correct 616 ms 504 KB Output is partially correct
41 Partially correct 624 ms 632 KB Output is partially correct
42 Partially correct 592 ms 408 KB Output is partially correct
43 Partially correct 645 ms 412 KB Output is partially correct
44 Partially correct 594 ms 372 KB Output is partially correct
45 Partially correct 725 ms 504 KB Output is partially correct
46 Partially correct 592 ms 376 KB Output is partially correct
47 Partially correct 586 ms 376 KB Output is partially correct
48 Partially correct 653 ms 516 KB Output is partially correct
49 Partially correct 604 ms 376 KB Output is partially correct
50 Partially correct 652 ms 376 KB Output is partially correct
51 Partially correct 622 ms 420 KB Output is partially correct
52 Partially correct 643 ms 368 KB Output is partially correct
53 Partially correct 634 ms 376 KB Output is partially correct
54 Partially correct 625 ms 480 KB Output is partially correct
55 Partially correct 607 ms 384 KB Output is partially correct
56 Partially correct 594 ms 368 KB Output is partially correct
57 Partially correct 604 ms 496 KB Output is partially correct
58 Partially correct 623 ms 504 KB Output is partially correct
59 Partially correct 600 ms 364 KB Output is partially correct
60 Correct 615 ms 368 KB Output is correct
61 Correct 606 ms 400 KB Output is correct
62 Correct 618 ms 372 KB Output is correct
63 Correct 593 ms 384 KB Output is correct
64 Correct 757 ms 504 KB Output is correct
65 Correct 661 ms 496 KB Output is correct
66 Correct 650 ms 624 KB Output is correct
67 Correct 643 ms 376 KB Output is correct
68 Correct 625 ms 380 KB Output is correct
69 Correct 626 ms 376 KB Output is correct
70 Correct 630 ms 508 KB Output is correct
71 Correct 614 ms 392 KB Output is correct
72 Correct 639 ms 376 KB Output is correct
73 Correct 616 ms 368 KB Output is correct
74 Correct 622 ms 368 KB Output is correct
75 Correct 621 ms 380 KB Output is correct
76 Correct 593 ms 388 KB Output is correct
77 Correct 705 ms 380 KB Output is correct
78 Correct 591 ms 492 KB Output is correct
79 Correct 608 ms 368 KB Output is correct
80 Correct 597 ms 376 KB Output is correct
81 Correct 930 ms 364 KB Output is correct
82 Correct 633 ms 512 KB Output is correct
83 Correct 596 ms 372 KB Output is correct
84 Correct 599 ms 492 KB Output is correct
85 Correct 605 ms 520 KB Output is correct
86 Correct 603 ms 364 KB Output is correct
87 Correct 594 ms 368 KB Output is correct
88 Correct 619 ms 504 KB Output is correct
89 Correct 937 ms 500 KB Output is correct
90 Correct 711 ms 508 KB Output is correct
91 Correct 612 ms 500 KB Output is correct