Submission #737283

# Submission time Handle Problem Language Result Execution time Memory
737283 2023-05-07T04:01:01 Z minhcool Rarest Insects (IOI22_insects) C++17
71.81 / 100
137 ms 720 KB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 3e5 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
vector<int> vc, vc2;
 
int cnt[N];
 
vector<iii> queries[13];
 
bool cmp(iii a, iii b){
	return (a.fi.fi + a.fi.se < b.fi.fi + b.fi.se);
}
 
bool in[N];
 
void moveinside(int u){
	if(in[u]) return;
	move_inside(u);
	in[u] = 1;
}
 
void moveoutside(int u){
	if(!in[u]) return;
	move_outside(u);
	in[u] = 0;
}
 
int p[N];
 
int mx[N], pref[N];
 
int min_cardinality(int n){
	for(int i = 0; i < n; i++) p[i] = i;
	shuffle(p, p + n, default_random_engine(7405));
	vc.pb(p[0]);
	moveinside(p[0]);
	for(int i = 1; i < n; i++){
		moveinside(p[i]);
		int temp = press_button();
		if(temp >= 2){
			moveoutside(p[i]);
			mx[p[i]] = vc.size();
			vc2.pb(p[i]);
		}
		else vc.pb(p[i]);
	}
	if(vc.size() <= 64){
		for(int i = 0; i < vc.size(); i++) cnt[i] = 1;
		for(int i = 0; i < vc2.size(); i++) queries[0].pb({{0, vc.size() - 1}, vc2[i]});
		for(auto it : vc) moveoutside(it);
	    int lst = vc.size() - 1;
		for(int i = 0; i <= 12; i++){
			if(!queries[i].size()) break;
   		   	sort(queries[i].begin(), queries[i].end(), cmp);
        	if((i & 1)){
        		//cout << i << "\n";
				//for(auto it : vc) assert(!in[it]);
				for(auto it : queries[i]){
					int mid = (it.fi.fi + it.fi.se) / 2;
					if(it.fi.fi == it.fi.se){
						cnt[it.fi.fi]++;
						continue;
					}
					for(int temp = it.fi.fi; temp <= mid; temp++) moveinside(vc[temp]);
					for(int temp = mid + 1; temp <= it.fi.se; temp++) moveoutside(vc[temp]);
					/*
    	            while(lst > mid){
    	            	moveoutside(vc[lst]);
    	                lst--;
    	            }
					while(lst < mid){
						lst++;
						moveinside(vc[lst]);
					}*/
					moveinside(it.se);
					if(press_button() >= 2) queries[i + 1].pb({{it.fi.fi, mid}, it.se});
					else queries[i + 1].pb({{mid + 1, it.fi.se}, it.se});
					moveoutside(it.se);
				}
   	    	}
   	 		else{
	    		//for(auto it : vc) if(!in[it]) cout << i << "\n";
	    		reverse(queries[i].begin(), queries[i].end());
	    		for(auto it : queries[i]){
					int mid = (it.fi.fi + it.fi.se) / 2;
					//assert(lst >= mid);
					if(it.fi.fi == it.fi.se){
						cnt[it.fi.fi]++;
						continue;
					}
					for(int temp = it.fi.fi; temp <= mid; temp++) moveinside(vc[temp]);
					for(int temp = mid + 1; temp <= it.fi.se; temp++) moveoutside(vc[temp]);
					moveinside(it.se);
					if(press_button() >= 2) queries[i + 1].pb({{it.fi.fi, mid}, it.se});
					else queries[i + 1].pb({{mid + 1, it.fi.se}, it.se});
					moveoutside(it.se);
				}
			}  
		}
		int mn = oo;
		for(int i = 0; i < vc.size(); i++) mn = min(mn, cnt[i]);
		return mn;
	}
	else{
		int l = 1, r = n / vc.size();
		while(l < r){
			int mid = (l + r + 1) >> 1;
			for(int i = 0; i < n; i++) moveoutside(i);
			for(int i = 0; i < n; i++){
				moveinside(i);			
				if(press_button() > mid) moveoutside(i);
			}
			int total = 0;
			for(int i = 0; i < n; i++) total += in[i];
			if(total == mid * vc.size()) l = mid;
			else r = mid - 1;
		}
		return l;
	}
}

Compilation message

insects.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(int i = 0; i < vc.size(); i++) cnt[i] = 1;
      |                  ~~^~~~~~~~~~~
insects.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int i = 0; i < vc2.size(); i++) queries[0].pb({{0, vc.size() - 1}, vc2[i]});
      |                  ~~^~~~~~~~~~~~
insects.cpp:115:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |   for(int i = 0; i < vc.size(); i++) mn = min(mn, cnt[i]);
      |                  ~~^~~~~~~~~~~
insects.cpp:65:10: warning: unused variable 'lst' [-Wunused-variable]
   65 |      int lst = vc.size() - 1;
      |          ^~~
insects.cpp:129:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |    if(total == mid * vc.size()) l = mid;
      |       ~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 288 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 9 ms 336 KB Output is correct
9 Correct 6 ms 336 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 4 ms 336 KB Output is correct
13 Correct 8 ms 336 KB Output is correct
14 Correct 8 ms 332 KB Output is correct
15 Correct 7 ms 336 KB Output is correct
16 Correct 6 ms 336 KB Output is correct
17 Correct 7 ms 336 KB Output is correct
18 Correct 5 ms 336 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 9 ms 336 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 288 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 9 ms 336 KB Output is correct
9 Correct 6 ms 336 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 4 ms 336 KB Output is correct
13 Correct 8 ms 336 KB Output is correct
14 Correct 8 ms 332 KB Output is correct
15 Correct 7 ms 336 KB Output is correct
16 Correct 6 ms 336 KB Output is correct
17 Correct 7 ms 336 KB Output is correct
18 Correct 5 ms 336 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 9 ms 336 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 320 KB Output is correct
23 Correct 10 ms 336 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 46 ms 396 KB Output is correct
26 Correct 45 ms 336 KB Output is correct
27 Correct 23 ms 336 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 28 ms 364 KB Output is correct
30 Correct 53 ms 352 KB Output is correct
31 Correct 23 ms 376 KB Output is correct
32 Correct 29 ms 372 KB Output is correct
33 Correct 36 ms 384 KB Output is correct
34 Correct 37 ms 456 KB Output is correct
35 Correct 37 ms 388 KB Output is correct
36 Correct 24 ms 344 KB Output is correct
37 Correct 51 ms 388 KB Output is correct
38 Correct 24 ms 348 KB Output is correct
39 Correct 27 ms 344 KB Output is correct
40 Correct 26 ms 344 KB Output is correct
41 Correct 6 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 21 ms 348 KB Output is correct
8 Correct 17 ms 208 KB Output is correct
9 Partially correct 125 ms 456 KB Output is partially correct
10 Partially correct 126 ms 456 KB Output is partially correct
11 Correct 29 ms 464 KB Output is correct
12 Correct 34 ms 344 KB Output is correct
13 Partially correct 74 ms 352 KB Output is partially correct
14 Partially correct 110 ms 652 KB Output is partially correct
15 Partially correct 56 ms 408 KB Output is partially correct
16 Partially correct 84 ms 452 KB Output is partially correct
17 Partially correct 68 ms 352 KB Output is partially correct
18 Partially correct 73 ms 456 KB Output is partially correct
19 Partially correct 80 ms 480 KB Output is partially correct
20 Partially correct 119 ms 600 KB Output is partially correct
21 Partially correct 133 ms 484 KB Output is partially correct
22 Partially correct 110 ms 456 KB Output is partially correct
23 Partially correct 78 ms 344 KB Output is partially correct
24 Correct 58 ms 332 KB Output is correct
25 Correct 39 ms 348 KB Output is correct
26 Correct 13 ms 352 KB Output is correct
27 Partially correct 118 ms 540 KB Output is partially correct
28 Partially correct 107 ms 532 KB Output is partially correct
29 Partially correct 109 ms 456 KB Output is partially correct
30 Partially correct 106 ms 468 KB Output is partially correct
31 Partially correct 67 ms 508 KB Output is partially correct
32 Partially correct 120 ms 720 KB Output is partially correct
33 Partially correct 89 ms 348 KB Output is partially correct
34 Partially correct 88 ms 348 KB Output is partially correct
35 Partially correct 137 ms 500 KB Output is partially correct
36 Partially correct 110 ms 504 KB Output is partially correct
37 Partially correct 93 ms 584 KB Output is partially correct
38 Partially correct 112 ms 456 KB Output is partially correct
39 Partially correct 90 ms 352 KB Output is partially correct
40 Partially correct 96 ms 344 KB Output is partially correct
41 Partially correct 97 ms 472 KB Output is partially correct
42 Partially correct 92 ms 612 KB Output is partially correct
43 Partially correct 15 ms 336 KB Output is partially correct
44 Partially correct 64 ms 452 KB Output is partially correct
45 Correct 31 ms 348 KB Output is correct
46 Correct 34 ms 336 KB Output is correct
47 Correct 41 ms 344 KB Output is correct
48 Correct 34 ms 332 KB Output is correct