Submission #957425

# Submission time Handle Problem Language Result Execution time Memory
957425 2024-04-03T16:49:24 Z yellowtoad Counting Mushrooms (IOI20_mushrooms) C++17
99.5595 / 100
7 ms 852 KB
#include "mushrooms.h"
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
#include <algorithm>
#define query use_machine
#define pb push_back
using namespace std;

int count_mushrooms(int n) {
	mt19937 rng(time(0));
		const int lim = 105;
		int pos, cnt, tmp;
		vector<int> a, b, v, q, ar, c, d;
		for (int i = 1; i < n; i++) ar.pb(i);
		for (int i = 1; i <= 10; i++) shuffle(ar.begin(),ar.end(),rng);
		ar.pb(0);
		reverse(ar.begin(),ar.end());
		if (n == 2) return 2-query({ar[0],ar[1]});
		a.pb(ar[0]);
		for (int i = 1; i <= 2; i++) {
			//if ((a.size() >= 2) || (b.size() >= 2)) break;
			pos = i+1;
			if (query({ar[0],ar[i]}) == 0) a.pb(ar[i]); 
			else b.pb(ar[i]);
		}
		while ((a.size() < lim) && (b.size() < lim)) {
			if ((pos+2 < n) && (a.size() >= 2) && (b.size() >= 2)) {
				tmp = query({a[0],ar[pos],a[1],b[0],ar[pos+1],b[1],ar[pos+2]});
				if (tmp%2 == 0) a.pb(ar[pos+2]);
				else b.pb(ar[pos+2]);
				if ((tmp-1)/2 == 0) a.pb(ar[pos]),b.pb(ar[pos+1]);
				else if ((tmp-1)/2 == 2) a.pb(ar[pos+1]),b.pb(ar[pos]);
				else {
					c.pb(ar[pos]); c.pb(ar[pos+1]);
					if (c.size() == 6) {
						tmp = query({a[0],c[0],c[1],a[1],b[0],c[2],c[3],b[1],c[4],c[5]});
						if (tmp%2 == 0) a.pb(c[4]), a.pb(c[5]);
						else b.pb(c[4]), b.pb(c[5]);
						if ((tmp-1)/2 == 0) a.pb(c[0]), a.pb(c[1]), b.pb(c[2]), b.pb(c[3]);
						else if ((tmp-1)/2 == 2) a.pb(c[2]), a.pb(c[3]), b.pb(c[0]), b.pb(c[1]);
						else {
							d.pb(c[0]); d.pb(c[1]); d.pb(c[2]); d.pb(c[3]);
							if (d.size() == 8) {
								tmp = query({a[0],d[0],d[1],d[2],d[3],a[1],d[4],d[5],d[6],d[7]});
								if (tmp == 0) a.pb(d[0]), a.pb(d[1]), a.pb(d[2]), a.pb(d[3]), a.pb(d[4]), a.pb(d[5]), a.pb(d[6]), a.pb(d[7]);
								else if (tmp == 1) a.pb(d[0]), a.pb(d[1]), a.pb(d[2]), a.pb(d[3]), b.pb(d[4]), b.pb(d[5]), b.pb(d[6]), b.pb(d[7]);
								else if (tmp == 2) b.pb(d[0]), b.pb(d[1]), b.pb(d[2]), b.pb(d[3]), a.pb(d[4]), a.pb(d[5]), a.pb(d[6]), a.pb(d[7]);
								else b.pb(d[0]), b.pb(d[1]), b.pb(d[2]), b.pb(d[3]), b.pb(d[4]), b.pb(d[5]), b.pb(d[6]), b.pb(d[7]);
								d.clear();
							}
						}
						c.clear();
					}
				}
				pos += 3;
			} else if (pos+1 < n) {
				if (a.size() >= 2) {
					tmp = query({a[0],ar[pos],a[1],ar[pos+1]});
					if (tmp == 0) a.pb(ar[pos]), a.pb(ar[pos+1]);
					else if (tmp == 1) a.pb(ar[pos]), b.pb(ar[pos+1]);
					else if (tmp == 2) b.pb(ar[pos]), a.pb(ar[pos+1]);
					else b.pb(ar[pos]), b.pb(ar[pos+1]);
				} else {
					tmp = query({b[0],ar[pos],b[1],ar[pos+1]});
					if (tmp == 0) b.pb(ar[pos]), b.pb(ar[pos+1]);
					else if (tmp == 1) b.pb(ar[pos]), a.pb(ar[pos+1]);
					else if (tmp == 2) a.pb(ar[pos]), b.pb(ar[pos+1]);
					else a.pb(ar[pos]), a.pb(ar[pos+1]);
				}
				pos += 2;
			} else break;
		}
		if (c.size() == 2) {
			tmp = query({a[0],c[0],a[1],c[1]});
			if (tmp == 0) a.pb(c[0]), a.pb(c[1]);
			else if (tmp == 1) a.pb(c[0]), b.pb(c[1]);
			else if (tmp == 2) b.pb(c[0]), a.pb(c[1]);
			else b.pb(c[0]), b.pb(c[1]);
		}
		if (c.size() == 4) {
			tmp = query({a[0],c[0],c[1],a[1],c[2],c[3]});
			if (tmp == 0) a.push_back(c[0]), a.push_back(c[1]), a.push_back(c[2]), a.push_back(c[3]);
			else if (tmp == 1) a.push_back(c[0]), a.push_back(c[1]), b.push_back(c[2]), b.push_back(c[3]);
			else if (tmp == 2) b.push_back(c[0]), b.push_back(c[1]), a.push_back(c[2]), a.push_back(c[3]);
			else b.push_back(c[0]), b.push_back(c[1]), b.push_back(c[2]), b.push_back(c[3]);
		}
		if (d.size()) {
			tmp = query({a[0],d[0],d[1],d[2],d[3]});
			if (tmp == 0) a.pb(d[0]), a.pb(d[1]), a.pb(d[2]), a.pb(d[3]);
			else b.pb(d[0]), b.pb(d[1]), b.pb(d[2]), b.pb(d[3]);
		}
		cnt = a.size();
		for (pos; pos < n; pos++) {
			v.pb(ar[pos]);
			if (v.size() == max(a.size(),b.size())) {
				if (a.size() >= b.size()) {
					q.clear();
					for (int i = 0; i < v.size(); i++) {
						q.pb(a[i]);
						q.pb(v[i]);
					}
					tmp = query(q);
					cnt += a.size()-(tmp+1)/2;
					if (tmp%2) b.pb(ar[pos]);
					else a.pb(ar[pos]);
				} else {
					q.clear();
					for (int i = 0; i < v.size(); i++) {
						q.pb(b[i]);
						q.pb(v[i]);
					}
					tmp = query(q);
					cnt += (tmp+1)/2;
					if (tmp%2) a.pb(ar[pos]);
					else b.pb(ar[pos]);
				}
				v.clear();
			}
		}
		if (v.size()) {
			if (a.size() >= b.size()) {
				q.clear();
				for (int i = 0; i < v.size(); i++) {
					q.pb(a[i]);
					q.pb(v[i]);
				}
				tmp = query(q);
				cnt += v.size()-(tmp+1)/2;
				if (tmp%2) b.pb(ar[pos]);
				else a.pb(ar[pos]);
			} else {
				q.clear();
				for (int i = 0; i < v.size(); i++) {
					q.pb(b[i]);
					q.pb(v[i]);
				}
				tmp = query(q);
				cnt += (tmp+1)/2;
				if (tmp%2) a.pb(ar[pos]);
				else b.pb(ar[pos]);
			}
		}
		return cnt;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:95:8: warning: statement has no effect [-Wunused-value]
   95 |   for (pos; pos < n; pos++) {
      |        ^~~
mushrooms.cpp:100:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |      for (int i = 0; i < v.size(); i++) {
      |                      ~~^~~~~~~~~~
mushrooms.cpp:110:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |      for (int i = 0; i < v.size(); i++) {
      |                      ~~^~~~~~~~~~
mushrooms.cpp:125:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
mushrooms.cpp:135:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 504 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 Correct 2 ms 468 KB Output is correct
7 Correct 6 ms 600 KB Output is correct
8 Correct 7 ms 600 KB Output is correct
9 Correct 6 ms 656 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 7 ms 600 KB Output is correct
12 Correct 7 ms 600 KB Output is correct
13 Correct 7 ms 600 KB Output is correct
14 Correct 4 ms 552 KB Output is correct
15 Correct 7 ms 600 KB Output is correct
16 Correct 7 ms 600 KB Output is correct
17 Correct 4 ms 552 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 7 ms 600 KB Output is correct
21 Correct 7 ms 600 KB Output is correct
22 Correct 7 ms 600 KB Output is correct
23 Correct 6 ms 600 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 6 ms 600 KB Output is correct
26 Correct 7 ms 600 KB Output is correct
27 Correct 7 ms 600 KB Output is correct
28 Partially correct 7 ms 600 KB Output is partially correct
29 Correct 7 ms 600 KB Output is correct
30 Correct 7 ms 600 KB Output is correct
31 Correct 6 ms 600 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
33 Correct 7 ms 600 KB Output is correct
34 Correct 7 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 6 ms 660 KB Output is correct
37 Correct 7 ms 600 KB Output is correct
38 Correct 7 ms 600 KB Output is correct
39 Correct 7 ms 756 KB Output is correct
40 Correct 7 ms 600 KB Output is correct
41 Correct 7 ms 600 KB Output is correct
42 Correct 7 ms 600 KB Output is correct
43 Correct 7 ms 600 KB Output is correct
44 Correct 7 ms 600 KB Output is correct
45 Correct 7 ms 600 KB Output is correct
46 Correct 7 ms 756 KB Output is correct
47 Correct 7 ms 600 KB Output is correct
48 Correct 6 ms 600 KB Output is correct
49 Correct 6 ms 600 KB Output is correct
50 Correct 6 ms 600 KB Output is correct
51 Correct 7 ms 600 KB Output is correct
52 Correct 6 ms 600 KB Output is correct
53 Correct 6 ms 600 KB Output is correct
54 Correct 7 ms 600 KB Output is correct
55 Correct 7 ms 600 KB Output is correct
56 Correct 7 ms 664 KB Output is correct
57 Correct 6 ms 600 KB Output is correct
58 Correct 7 ms 600 KB Output is correct
59 Correct 7 ms 600 KB Output is correct
60 Correct 7 ms 600 KB Output is correct
61 Correct 7 ms 600 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 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 1 ms 344 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 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 0 ms 344 KB Output is correct
76 Correct 0 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 352 KB Output is correct
80 Correct 0 ms 352 KB Output is correct
81 Correct 0 ms 356 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 0 ms 356 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 1 ms 356 KB Output is correct
86 Correct 0 ms 356 KB Output is correct
87 Correct 0 ms 352 KB Output is correct
88 Correct 0 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