Submission #1060093

#TimeUsernameProblemLanguageResultExecution timeMemory
1060093DorostWefRarest Insects (IOI22_insects)C++17
100 / 100
42 ms940 KiB
    #include "insects.h"
    #include <bits/stdc++.h>
     
    using namespace std;
     
    int min_cardinality(int N) {
    	vector <int> a;
    	int n = N;
    	int k = 0;
    	vector <int> d;
    	for (int i = 0; i < n; i++) {
    		move_inside (i);
    		if (press_button() >= 2) {
    			move_outside (i);
    			a.push_back(i);
    		} else {
    			d.push_back(i);
    			k++;
    		}
    	}
    	for (int i : d)
    		move_outside (i);
    	int ans = 1;
    	vector <int> b, c;
    	while ((int)a.size() >= k) {
    		for (int i : c)
    			move_outside (i);
    		n = (int)a.size();
    //		cout << n << endl;
    		int m = (n + 2 * k - 1) / (2 * k); 
    		int cnt = 0;
    		b.clear();
    		c.clear();
    		for (int i = 0; i < n; i++) {
    			move_inside (a[i]);
    			if (press_button() > m) {
    				b.push_back (a[i]);
    				move_outside (a[i]);
    			} else {
    				cnt++;
    				c.push_back (a[i]);
    			}
    		}
    		if (cnt == k * m) {
    			a = b;
    			ans += m;
    		} else {
    			a = c;
    		}
    	}
    	return ans;
    }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...