Submission #1314514

#TimeUsernameProblemLanguageResultExecution timeMemory
1314514PlayVoltzRarest Insects (IOI22_insects)C++20
Compilation error
0 ms0 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

int min_cardinality(int n){
	vector<int> ord;
	for (int i=0; i<n; ++i)ord.pb(i);
	random_device rd;
	mt19937 gen(rd());
	shuffle(ord.begin(), ord.end(), gen);
	int uq=1;
	move_inside(0);
	vector<bool> got(n, 0), ban(n, 0);
	got[0]=1;
	for (int i:ord)if (i){
		move_inside(i);
		got[i]=1;
		if (press_button()==2)move_outside(i), got[i]=0;
		else ++uq;
	}
	int low=1, high=n/uq+1;
	while (low+1<high){
		int mid=(low+high)/2, c=0;
		vector<bool> toomuch(n, 0), added(n, 0);
		for (int i:ord)if (got[i])++c;
		for (int i:ord)if (!got[i]&&!ban[i]){
			move_inside(i);
			got[i]=1;
			added[i]=1;
			if (press_button()>mid)move_outside(i), got[i]=0, added[i]=0, toomuch[i]=1;
			else ++c;
			else ++c;
		}
		if (c==uq*mid)low=mid;
		else{
			high=mid;
			for (int i:ord)if (added[i])move_outside(i), got[i]=0;
			for (int i:ord)if (toomuch[i])ban[i]=1;
		}
	}
	return low;
}

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:38:25: error: expected '}' before 'else'
   38 |                         else ++c;
      |                         ^~~~
insects.cpp:32:53: note: to match this '{'
   32 |                 for (int i:ord)if (!got[i]&&!ban[i]){
      |                                                     ^
insects.cpp:40:21: error: 'c' was not declared in this scope
   40 |                 if (c==uq*mid)low=mid;
      |                     ^
insects.cpp:40:27: error: 'mid' was not declared in this scope
   40 |                 if (c==uq*mid)low=mid;
      |                           ^~~
insects.cpp:43:44: error: 'added' was not declared in this scope
   43 |                         for (int i:ord)if (added[i])move_outside(i), got[i]=0;
      |                                            ^~~~~
insects.cpp:44:44: error: 'toomuch' was not declared in this scope
   44 |                         for (int i:ord)if (toomuch[i])ban[i]=1;
      |                                            ^~~~~~~
insects.cpp:46:9: warning: no return statement in function returning non-void [-Wreturn-type]
   46 |         }
      |         ^
insects.cpp: At global scope:
insects.cpp:47:9: error: expected unqualified-id before 'return'
   47 |         return low;
      |         ^~~~~~
insects.cpp:48:1: error: expected declaration before '}' token
   48 | }
      | ^