Submission #603416

# Submission time Handle Problem Language Result Execution time Memory
603416 2022-07-24T06:34:14 Z Red_Inside Counting Mushrooms (IOI20_mushrooms) C++17
25 / 100
135 ms 780 KB
#include "mushrooms.h"
#include <bits/stdc++.h>

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

using namespace std;
const int maxn=2e5+100,LOG=17,mod=1e9+7;
int block = 226, timer = 0;
const ld EPS = 1e-18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define bt(i) (1 << (i))
//#define int ll
const int inf=2e9;
#define y1 yy
#define prev pre
#define pii pair <int, int>

int count_mushrooms(int n)
{
	vector <int> was, fi, se, que;
	int ret = 0;
	was.assign(n + 2, 0);
	was[0] = 1;
	fi.pb(0);
	que.clear();
	que.pb(0);
	que.pb(1);
	ret = use_machine(que);
	if(ret == 1)
	{
		was[1] = 2;
		se.pb(1);
	}
	else
	{
		was[1] = 1;
		fi.pb(1);
	}
	que.clear();
	if(n <= 2)
	{
		return fi.size();
	}
	que.pb(0);
	que.pb(2);
	ret = use_machine(que);
	if(ret == 1)
	{
		was[2] = 2;
		se.pb(2);
	}
	else
	{
		was[2] = 1;
		fi.pb(2);
	}
	for(int iter = 1; iter * 2 - 1 <= n-3; ++iter)
	{
		int pos = rng() % n;
		while(was[pos]) pos = rng() % n;
		if(n - 3 == 2*iter- 1)
		{
			que.clear();
			que.pb(0);
			que.pb(pos);
			ret = use_machine(que);
			if(ret == 1)
			{
				was[pos] = 2;
				se.pb(pos);
			}
			else
			{
				was[pos] = 1;
				fi.pb(pos);
			}
			break;
		}
		was[pos] = 1;
		int pos2 = rng() % n;
		while(was[pos2]) pos2 = rng() % n;
		if(fi.size() >= 2)
		{
			que.clear();
			que.pb(fi[0]);
			que.pb(pos);
			que.pb(fi[1]);
			que.pb(pos2);
			ret = use_machine(que);
			if(ret % 2 == 1)
			{
				was[pos2] = 2;
				se.pb(pos2);
			}
			else
			{
				was[pos2] = 1;
				fi.pb(pos2);
			}
			if(ret / 2 == 1)
			{
				was[pos] = 2;
				se.pb(pos);
			}
			else
			{
				was[pos] = 1;
				fi.pb(pos);
			}
		}
		else
		{
			que.clear();
			que.pb(se[0]);
			que.pb(pos);
			que.pb(se[1]);
			que.pb(pos2);
			ret = use_machine(que);
			if(ret % 2 == 0)
			{
				was[pos2] = 2;
				se.pb(pos2);
			}
			else
			{
				was[pos2] = 1;
				fi.pb(pos2);
			}
			if(ret / 2 == 0)
			{
				was[pos] = 2;
				se.pb(pos);
			}
			else
			{
				was[pos] = 1;
				fi.pb(pos);
			}
		}
	}
	int ans = fi.size();
	if(se.size() > fi.size())
	{
		while(true)
		{
			int uk = 0;
			que.clear();
			forn(0, i, n-1)
			{
				if(!was[i])
				{
					que.pb(se[uk++]);
					que.pb(i);
					if(uk == se.size()) break;
				}
			}
			if(que.size() == 0) break;
			ret = use_machine(que);
			ans += ret / 2 + ret % 2;
			for(int i = 1; i < que.size(); i += 2)
			{
				was[que[i]] = 1;
			}
		}
	}
	else
	{
		while(true)
		{
			int uk = 0;
			que.clear();
			forn(0, i, n-1)
			{
				if(!was[i])
				{
					que.pb(fi[uk++]);
					que.pb(i);
					if(uk == fi.size()) break;
				}
			}
			if(que.size() == 0) break;
			ret = use_machine(que);
			ans += ((int)que.size()) / 2 - (ret / 2 + ret % 2);
			for(int i = 1; i < que.size(); i += 2)
			{
				was[que[i]] = 1;
			}
		}
	}
	return ans;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:168:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  168 |      if(uk == se.size()) break;
      |         ~~~^~~~~~~~~~~~
mushrooms.cpp:174:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  174 |    for(int i = 1; i < que.size(); i += 2)
      |                   ~~^~~~~~~~~~~~
mushrooms.cpp:192:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  192 |      if(uk == fi.size()) break;
      |         ~~~^~~~~~~~~~~~
mushrooms.cpp:198:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  198 |    for(int i = 1; i < que.size(); i += 2)
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 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 2 ms 208 KB Output is correct
6 Partially correct 6 ms 208 KB Output is partially correct
7 Partially correct 96 ms 520 KB Output is partially correct
8 Partially correct 112 ms 556 KB Output is partially correct
9 Partially correct 84 ms 620 KB Output is partially correct
10 Partially correct 74 ms 484 KB Output is partially correct
11 Partially correct 111 ms 440 KB Output is partially correct
12 Partially correct 55 ms 516 KB Output is partially correct
13 Partially correct 115 ms 572 KB Output is partially correct
14 Partially correct 32 ms 408 KB Output is partially correct
15 Partially correct 83 ms 528 KB Output is partially correct
16 Partially correct 81 ms 524 KB Output is partially correct
17 Partially correct 43 ms 352 KB Output is partially correct
18 Partially correct 87 ms 560 KB Output is partially correct
19 Partially correct 103 ms 528 KB Output is partially correct
20 Partially correct 93 ms 488 KB Output is partially correct
21 Partially correct 120 ms 500 KB Output is partially correct
22 Partially correct 76 ms 536 KB Output is partially correct
23 Partially correct 113 ms 428 KB Output is partially correct
24 Partially correct 47 ms 404 KB Output is partially correct
25 Partially correct 135 ms 568 KB Output is partially correct
26 Partially correct 84 ms 536 KB Output is partially correct
27 Partially correct 95 ms 424 KB Output is partially correct
28 Partially correct 113 ms 448 KB Output is partially correct
29 Partially correct 83 ms 444 KB Output is partially correct
30 Partially correct 90 ms 520 KB Output is partially correct
31 Partially correct 110 ms 416 KB Output is partially correct
32 Partially correct 89 ms 524 KB Output is partially correct
33 Partially correct 104 ms 456 KB Output is partially correct
34 Partially correct 98 ms 536 KB Output is partially correct
35 Partially correct 93 ms 524 KB Output is partially correct
36 Partially correct 84 ms 532 KB Output is partially correct
37 Partially correct 103 ms 536 KB Output is partially correct
38 Partially correct 91 ms 516 KB Output is partially correct
39 Partially correct 105 ms 780 KB Output is partially correct
40 Partially correct 82 ms 420 KB Output is partially correct
41 Partially correct 98 ms 520 KB Output is partially correct
42 Partially correct 53 ms 540 KB Output is partially correct
43 Partially correct 80 ms 540 KB Output is partially correct
44 Partially correct 91 ms 520 KB Output is partially correct
45 Partially correct 77 ms 456 KB Output is partially correct
46 Partially correct 88 ms 656 KB Output is partially correct
47 Partially correct 107 ms 524 KB Output is partially correct
48 Partially correct 87 ms 528 KB Output is partially correct
49 Partially correct 102 ms 624 KB Output is partially correct
50 Partially correct 85 ms 424 KB Output is partially correct
51 Partially correct 98 ms 532 KB Output is partially correct
52 Partially correct 99 ms 536 KB Output is partially correct
53 Partially correct 87 ms 516 KB Output is partially correct
54 Partially correct 87 ms 588 KB Output is partially correct
55 Partially correct 95 ms 464 KB Output is partially correct
56 Partially correct 98 ms 516 KB Output is partially correct
57 Partially correct 66 ms 452 KB Output is partially correct
58 Partially correct 90 ms 516 KB Output is partially correct
59 Partially correct 85 ms 528 KB Output is partially correct
60 Partially correct 103 ms 524 KB Output is partially correct
61 Partially correct 97 ms 540 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 1 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 1 ms 208 KB Output is correct
68 Correct 0 ms 208 KB Output is correct
69 Correct 0 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 0 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 1 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 0 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 0 ms 208 KB Output is correct
91 Correct 0 ms 208 KB Output is correct