Submission #1079065

# Submission time Handle Problem Language Result Execution time Memory
1079065 2024-08-28T10:16:01 Z anango Counting Mushrooms (IOI20_mushrooms) C++17
10 / 100
136 ms 596 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

int simple_check(int i1, int i2) {
    //return whether i1!=i2
    return use_machine({i1,i2});
}

pair<int,int> double_check(pair<int,int> known, int known_type, pair<int,int> unknown) {
    //returns the types of two values by testing them against the known
    int ct = use_machine({unknown.first,known.first,unknown.second,known.second});
    if (known_type==1) {
        ct=3-ct;
    }
    return {ct%2,ct/2};
}

pair<int,int> simple_count(vector<int> known, int known_type, vector<int> unknown) {
    //return {type of first unknown, count of A among the rest of the unknowns}
    assert(unknown.size()<=known.size());
    assert(unknown.size()>0);
    vector<int> m={unknown[0]};
    for (int i=0; i<known.size(); i++) {
        m.push_back(known[i]);
        if (i+1<unknown.size()) {
            m.push_back(unknown[i+1]);
        }
    }
    int ct = use_machine(m);
    if (known_type==1) {
        ct = ((int)2*unknown.size())-1-ct;
    }
    return {ct%2,ct/2};

}

int count_mushrooms(int n) {
	/*std::vector<int> m;
	for (int i = 0; i < n; i++)
		m.push_back(i);
	int c1 = use_machine(m);
	m = {0, 1};
	int c2 = use_machine(m);*/

    //suppose we know 100 As
    //given a group of at most 99 mushrooms, we can easily count the number of As
    //by inserting them in between the previous As
    //and each B will increase the number of differing adjacent pairs by 1
    //we can even insert something before all the As, and we have full knowledge of what this is
    //since all the other deltas will be even, but if this is B then the entire delta will be odd
    //since the B contributes 1 to the result
    //thus this gives a k+n/k solution
    //like 632+316 queries if we naively find the group of As
    //maybe, we can increase the size of the segment gradually
    //starting with just one A
    //we can put 1 before the A to test it
    //and keep a segment of As and a segment of Bs
    //and use the longer one each time to test, and every time we gain info of one letter as well
    //worst case is if it keeps alternating As and Bs
    //then we need upto 631 queries
    //constraints misread
    //n=20k not 100k
    //ok so the first method uses 141*3 queries
    //second uses like 284 queries, decent
    //ok but we can do something a bit different
    //suppose we know 2 As (or Bs, that takes like 4 queries or something tiny)
    //then you can explicitly test 2 characters by putting MAGA where M and G are the 2 testing characters
    //since G increases it by 2 if B and M increases it by 1 if B
    //so what you can do is use 100 queries to find out 200 letters
    //then put all the As together and use the first method
    //that is, unfortunately, still 284 queries even when we optimise it using 141 queries in the first stage
    //somehow combine these methods
    //start by explicitly testing 2 characters each time upto some limit l1 queries
    //then keep doing the normal test with 1 new character each time
    //manual binary search to find optimal l1
    //results: l1=80 and l2=244
    //that's like 90 points
    //just implement this forget about 100
    if (n<30000) {
        int ct=0;
        for (int i=1; i<n; i++) {
            ct+=simple_check(0,i);
        }
        return n-ct;
    }
    int l1 = 80;
    int l2 = 246; //some space

    //first do 4 queries to find AA
    
    int ans = 0;
	return n-ans;
}

Compilation message

mushrooms.cpp: In function 'std::pair<int, int> simple_count(std::vector<int>, int, std::vector<int>)':
mushrooms.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i=0; i<known.size(); i++) {
      |                   ~^~~~~~~~~~~~~
mushrooms.cpp:26:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (i+1<unknown.size()) {
      |             ~~~^~~~~~~~~~~~~~~
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:87:9: warning: unused variable 'l1' [-Wunused-variable]
   87 |     int l1 = 80;
      |         ^~
mushrooms.cpp:88:9: warning: unused variable 'l2' [-Wunused-variable]
   88 |     int l2 = 246; //some space
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Partially correct 8 ms 344 KB Output is partially correct
7 Partially correct 116 ms 344 KB Output is partially correct
8 Partially correct 129 ms 344 KB Output is partially correct
9 Partially correct 122 ms 344 KB Output is partially correct
10 Partially correct 104 ms 344 KB Output is partially correct
11 Partially correct 122 ms 344 KB Output is partially correct
12 Partially correct 114 ms 344 KB Output is partially correct
13 Partially correct 117 ms 344 KB Output is partially correct
14 Partially correct 50 ms 344 KB Output is partially correct
15 Partially correct 117 ms 344 KB Output is partially correct
16 Partially correct 99 ms 344 KB Output is partially correct
17 Partially correct 47 ms 344 KB Output is partially correct
18 Partially correct 92 ms 344 KB Output is partially correct
19 Partially correct 107 ms 344 KB Output is partially correct
20 Partially correct 108 ms 344 KB Output is partially correct
21 Partially correct 111 ms 344 KB Output is partially correct
22 Partially correct 100 ms 344 KB Output is partially correct
23 Partially correct 120 ms 344 KB Output is partially correct
24 Partially correct 47 ms 344 KB Output is partially correct
25 Partially correct 114 ms 344 KB Output is partially correct
26 Partially correct 100 ms 344 KB Output is partially correct
27 Partially correct 109 ms 344 KB Output is partially correct
28 Partially correct 111 ms 344 KB Output is partially correct
29 Partially correct 118 ms 344 KB Output is partially correct
30 Partially correct 89 ms 344 KB Output is partially correct
31 Partially correct 108 ms 344 KB Output is partially correct
32 Partially correct 112 ms 344 KB Output is partially correct
33 Partially correct 118 ms 344 KB Output is partially correct
34 Partially correct 110 ms 344 KB Output is partially correct
35 Partially correct 128 ms 344 KB Output is partially correct
36 Partially correct 110 ms 344 KB Output is partially correct
37 Partially correct 118 ms 344 KB Output is partially correct
38 Partially correct 127 ms 344 KB Output is partially correct
39 Partially correct 126 ms 344 KB Output is partially correct
40 Partially correct 103 ms 344 KB Output is partially correct
41 Partially correct 123 ms 344 KB Output is partially correct
42 Partially correct 98 ms 344 KB Output is partially correct
43 Partially correct 123 ms 344 KB Output is partially correct
44 Partially correct 115 ms 344 KB Output is partially correct
45 Partially correct 129 ms 344 KB Output is partially correct
46 Partially correct 112 ms 344 KB Output is partially correct
47 Partially correct 119 ms 344 KB Output is partially correct
48 Partially correct 99 ms 344 KB Output is partially correct
49 Partially correct 119 ms 344 KB Output is partially correct
50 Partially correct 116 ms 344 KB Output is partially correct
51 Partially correct 98 ms 344 KB Output is partially correct
52 Partially correct 114 ms 344 KB Output is partially correct
53 Partially correct 128 ms 344 KB Output is partially correct
54 Partially correct 122 ms 344 KB Output is partially correct
55 Partially correct 116 ms 344 KB Output is partially correct
56 Partially correct 110 ms 344 KB Output is partially correct
57 Partially correct 136 ms 344 KB Output is partially correct
58 Partially correct 108 ms 340 KB Output is partially correct
59 Partially correct 120 ms 344 KB Output is partially correct
60 Partially correct 104 ms 596 KB Output is partially correct
61 Partially correct 116 ms 344 KB Output is partially correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 1 ms 344 KB Output is correct
76 Correct 1 ms 344 KB Output is correct
77 Correct 0 ms 344 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 0 ms 344 KB Output is correct
81 Correct 0 ms 344 KB Output is correct
82 Correct 0 ms 352 KB Output is correct
83 Correct 0 ms 344 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 0 ms 344 KB Output is correct
86 Correct 0 ms 344 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 1 ms 344 KB Output is correct
89 Correct 0 ms 344 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct