Submission #1042643

# Submission time Handle Problem Language Result Execution time Memory
1042643 2024-08-03T08:53:48 Z DorostWef Counting Mushrooms (IOI20_mushrooms) C++17
Compilation error
0 ms 0 KB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

int count_mushrooms(int n) {
	vector <int> a;
	for (int i = 1; i < n; i++)
		a.push_back(i);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	shuffle(a.begin(), a.end(), rng)
	int ans = 1;
	vector <int> A = {0}, B;
	while (!a.empty()) {
		vector <int> v;
		if ((int)A.size() >= (int)B.size()) {
			int t = 0;
			for (int i = 0; i < (int) A.size() && !a.empty(); i++) {
				t++;
				v.push_back(A[i]);
				v.push_back(a.back());
				a.pop_back();
			}
			int k = use_machine (v);
			if (k % 2)
				B.push_back(v.back());
			else
				A.push_back(v.back());
			k = t - ((k + 1) / 2);
			ans += k;
		} else {
			int t = 0;
			for (int i = 0; i < (int) B.size() && !a.empty(); i++) {
				t++;
				v.push_back(a.back());
				v.push_back(B[i]);
				a.pop_back();
			}
			int k = use_machine (v);
			if (k % 2)
				A.push_back(v[0]);
			else
				B.push_back(v[0]);
			k = ((k + 1) / 2);
			ans += k;
		}
	}
	return ans;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:11:34: error: expected ';' before 'int'
   11 |  shuffle(a.begin(), a.end(), rng)
      |                                  ^
      |                                  ;
   12 |  int ans = 1;
      |  ~~~                              
mushrooms.cpp:30:4: error: 'ans' was not declared in this scope; did you mean 'abs'?
   30 |    ans += k;
      |    ^~~
      |    abs
mushrooms.cpp:45:4: error: 'ans' was not declared in this scope; did you mean 'abs'?
   45 |    ans += k;
      |    ^~~
      |    abs
mushrooms.cpp:48:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   48 |  return ans;
      |         ^~~
      |         abs