Submission #800335

# Submission time Handle Problem Language Result Execution time Memory
800335 2023-08-01T13:28:25 Z lukameladze Counting Mushrooms (IOI20_mushrooms) C++17
92.2449 / 100
7 ms 524 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair <int, int>
#define pb push_back
const int MX = 3e5 + 5;
int count_mushrooms(int n) {
	vector <int> to_ask; vector <int> res(n, 0);
	res[0] = 1; // res[i] == (1 _ 'A')        res[i] == (0 _ 'B')
	
	to_ask = {0, 1};
	int c = use_machine(to_ask);
	res[1] = (c ? 0 : 1); 
	if (n == 2) {
		return res[0] + res[1];
	}
	to_ask = {0, 2};
	c = use_machine(to_ask);
	res[2] = (c ? 0 : 1);
	int x, y;
	if (res[0] == res[1]) x = 0, y = 1; 
	else if (res[0] == res[2]) x = 0, y = 2;
	else if (res[1] == res[2]) x = 1, y = 2;
	int ans = (res[0] + res[1] + res[2]);
	int xr = res[x] ^ 1;
	int B = min(n, 180);
	for (int i = 3; i < B; i+=2) {
		if (i == B - 1) {
			to_ask = {0, i}; int c = use_machine(to_ask); res[i] = (c ? 0 : 1);
			ans += res[i]; 
			continue;
		}
		to_ask = {i, x, i + 1, y};
		int c = use_machine(to_ask);
		if (c == 0) { res[i] = res[i + 1] = 1; }
		else if (c == 1) { res[i] = 0; res[i + 1] = 1; }
		else if (c == 2) { res[i] = 1; res[i + 1] = 0; }
		else if (c == 3) { res[i] = res[i + 1] = 0;  }
		res[i] ^= xr; res[i + 1] ^= xr;
		ans += (res[i] + res[i + 1]); 
	}
	vector <int> vec[2];
	for (int i = 0; i < B; i++) {
		vec[res[i]].pb(i);
	}
	// cout<<"sizes "<<vec[0].size()<<" "<<vec[1].size()<<"\n";
	vector <int> my_vec;
	if (vec[0].size() > vec[1].size()) xr = 0, my_vec = vec[0];
	else xr = 1, my_vec = vec[1];
	vector <int> cur_vec;
	for (int i = B; i < n; i++) {
		cur_vec.pb(i);
		//cout<<i<<" --- > "<<cur_vec.size()<<"\n";
		if (cur_vec.size() == (int)vec[xr].size() || i == n - 1) {
			vector <int> to_ask;
			int all = (int)cur_vec.size();
			for (int i = 0; i < (int)cur_vec.size(); i++) {
					to_ask.pb(vec[xr][i]); to_ask.pb(cur_vec[i]);
			}
			int c = use_machine(to_ask);
			if (c % 2 == 0) { // AUAUAUAUAU     if (c % 2 == 0)  then U = A
				// res[i] == xr
				int diff = c / 2;
				if (xr == 0) ans += diff;
				else ans += (all - diff);
				vec[xr].pb(i);
			} else if (c % 2 == 1) { 
				int diff = 1 + c / 2;
				if (xr == 0) ans += diff;
				else ans += all - diff;
				vec[xr ^ 1].pb(i);
			}
			xr = (vec[0].size() > vec[1].size() ? 0 : 1);
			cur_vec.clear();
		}
	}
	return ans;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:56:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |   if (cur_vec.size() == (int)vec[xr].size() || i == n - 1) {
      |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:27:16: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |  int xr = res[x] ^ 1;
      |                ^
mushrooms.cpp:35:10: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |   to_ask = {i, x, i + 1, y};
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 5 ms 336 KB Output is correct
8 Correct 5 ms 396 KB Output is correct
9 Correct 6 ms 388 KB Output is correct
10 Correct 5 ms 392 KB Output is correct
11 Partially correct 7 ms 336 KB Output is partially correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Partially correct 6 ms 380 KB Output is partially correct
16 Partially correct 6 ms 400 KB Output is partially correct
17 Correct 3 ms 336 KB Output is correct
18 Correct 4 ms 336 KB Output is correct
19 Partially correct 6 ms 524 KB Output is partially correct
20 Correct 5 ms 388 KB Output is correct
21 Correct 4 ms 404 KB Output is correct
22 Partially correct 5 ms 428 KB Output is partially correct
23 Correct 5 ms 336 KB Output is correct
24 Correct 4 ms 336 KB Output is correct
25 Partially correct 6 ms 336 KB Output is partially correct
26 Partially correct 5 ms 404 KB Output is partially correct
27 Partially correct 5 ms 336 KB Output is partially correct
28 Partially correct 6 ms 396 KB Output is partially correct
29 Partially correct 6 ms 404 KB Output is partially correct
30 Partially correct 5 ms 336 KB Output is partially correct
31 Partially correct 6 ms 336 KB Output is partially correct
32 Partially correct 5 ms 408 KB Output is partially correct
33 Partially correct 5 ms 336 KB Output is partially correct
34 Partially correct 6 ms 336 KB Output is partially correct
35 Partially correct 5 ms 400 KB Output is partially correct
36 Partially correct 6 ms 404 KB Output is partially correct
37 Partially correct 6 ms 336 KB Output is partially correct
38 Partially correct 6 ms 336 KB Output is partially correct
39 Partially correct 6 ms 464 KB Output is partially correct
40 Partially correct 5 ms 336 KB Output is partially correct
41 Partially correct 6 ms 336 KB Output is partially correct
42 Partially correct 6 ms 336 KB Output is partially correct
43 Partially correct 6 ms 336 KB Output is partially correct
44 Partially correct 6 ms 388 KB Output is partially correct
45 Partially correct 7 ms 336 KB Output is partially correct
46 Partially correct 5 ms 396 KB Output is partially correct
47 Partially correct 7 ms 392 KB Output is partially correct
48 Partially correct 4 ms 400 KB Output is partially correct
49 Partially correct 5 ms 336 KB Output is partially correct
50 Partially correct 5 ms 400 KB Output is partially correct
51 Partially correct 5 ms 404 KB Output is partially correct
52 Partially correct 6 ms 336 KB Output is partially correct
53 Partially correct 7 ms 336 KB Output is partially correct
54 Partially correct 5 ms 336 KB Output is partially correct
55 Partially correct 5 ms 404 KB Output is partially correct
56 Partially correct 6 ms 400 KB Output is partially correct
57 Partially correct 6 ms 400 KB Output is partially correct
58 Partially correct 5 ms 380 KB Output is partially correct
59 Partially correct 6 ms 336 KB Output is partially correct
60 Partially correct 6 ms 392 KB Output is partially correct
61 Partially correct 5 ms 400 KB Output is partially correct
62 Correct 0 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 0 ms 208 KB Output is correct
66 Correct 0 ms 208 KB Output is correct
67 Correct 0 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 1 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 0 ms 208 KB Output is correct
74 Correct 0 ms 208 KB Output is correct
75 Correct 0 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 0 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 0 ms 208 KB Output is correct
84 Correct 0 ms 208 KB Output is correct
85 Correct 0 ms 208 KB Output is correct
86 Correct 0 ms 208 KB Output is correct
87 Correct 1 ms 208 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