답안 #630906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630906 2022-08-17T10:21:33 Z MateGiorbelidze 드문 곤충 (IOI22_insects) C++17
54.74 / 100
163 ms 340 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define sc second

int n;

int min_cardinality(int N) {
	n = N;
	
	move_inside(0);
	
	vector <int> a , b;
	a.pb(0);
	
	for (int i = 1; i < n; i++) {
		
		move_inside(i);
		
		int ans = press_button();
		 
		if (ans == 2) {
			
			move_outside(i);
			b.pb(i);
			
		}
		else a.pb(i);
		
	}
	
	if (a.size() > b.size()) return 1;
	
	int fr[a.size() + 1];
	
	pair<int,int> d[b.size()];
	
	for (int i = 0; i < b.size(); i++)
		d[i] = {0 , a.size() - 1};
	
	for (int i = 0; i < a.size(); i++)
		fr[i] = 1;
	
	stack < pair<int,int> > st;
	int l = 0, r = a.size() - 1;
	st.push({0 , a.size() - 1});
	
	while (!st.empty()) {
		
		pair<int,int> k = st.top();
		st.pop();
		
		if (k.ff == k.sc) {
			
			for (int i = 0; i < b.size(); i++) {
				
				if (d[i] == k) {
					
					fr[k.ff]++;
					
				}
				
			}
			
		}
		else {
			
			int m = (k.ff + k.sc) / 2;
			
			for (int i = k.ff; i < l; i++)
				move_inside(a[i]);
			
			for (int i = l; i < k.ff; i++)
				move_outside(a[i]);
				
			for (int i = r + 1; i <= m; i++)
				move_inside(a[i]);
				
			for (int i = m + 1; i <= r; i++)
				move_outside(a[i]);		
			
			int cnt1 = 0 , cnt2 = 0;
				
			for (int i = 0; i < b.size(); i++) {
				
				if (d[i] == k) {
					
					move_inside(b[i]);
					
					int ans = press_button();
					
					if (ans == 2) {
						
						cnt1++;
						
						d[i] = {k.ff , m};
						
					}
					else {
						
						cnt2++;
						
						d[i] = {m + 1 , k.sc};
						
					}
					
					move_outside(b[i]);
					
				}
				
			}
			
			if (cnt2 > 0) st.push({m + 1, k.sc});
			if (cnt1 > 0) st.push({k.ff, m});
			
			l = k.ff; r = k.sc;
			
		}

	}
	int mn = INT_MAX;
	
	for (int i = 0; i < a.size(); i++)
		mn = min(mn , fr[i]);
		
	return mn;	
		
	
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for (int i = 0; i < b.size(); i++)
      |                  ~~^~~~~~~~~~
insects.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i = 0; i < a.size(); i++)
      |                  ~~^~~~~~~~~~
insects.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    for (int i = 0; i < b.size(); i++) {
      |                    ~~^~~~~~~~~~
insects.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |    for (int i = 0; i < b.size(); i++) {
      |                    ~~^~~~~~~~~~
insects.cpp:127:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |  for (int i = 0; i < a.size(); i++)
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 9 ms 208 KB Output is correct
9 Correct 12 ms 300 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 10 ms 208 KB Output is correct
13 Correct 10 ms 300 KB Output is correct
14 Correct 9 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 9 ms 296 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 9 ms 208 KB Output is correct
19 Correct 6 ms 296 KB Output is correct
20 Correct 12 ms 208 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 4 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 9 ms 208 KB Output is correct
9 Correct 12 ms 300 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 10 ms 208 KB Output is correct
13 Correct 10 ms 300 KB Output is correct
14 Correct 9 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 9 ms 296 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 9 ms 208 KB Output is correct
19 Correct 6 ms 296 KB Output is correct
20 Correct 12 ms 208 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 4 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 11 ms 340 KB Output is correct
25 Correct 48 ms 288 KB Output is correct
26 Correct 48 ms 304 KB Output is correct
27 Correct 15 ms 208 KB Output is correct
28 Correct 7 ms 208 KB Output is correct
29 Correct 32 ms 300 KB Output is correct
30 Correct 69 ms 208 KB Output is correct
31 Correct 40 ms 304 KB Output is correct
32 Correct 38 ms 208 KB Output is correct
33 Correct 34 ms 300 KB Output is correct
34 Correct 32 ms 208 KB Output is correct
35 Correct 32 ms 208 KB Output is correct
36 Correct 44 ms 300 KB Output is correct
37 Correct 71 ms 304 KB Output is correct
38 Correct 51 ms 220 KB Output is correct
39 Correct 64 ms 300 KB Output is correct
40 Correct 50 ms 308 KB Output is correct
41 Correct 10 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 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 1 ms 208 KB Output is correct
7 Correct 26 ms 304 KB Output is correct
8 Correct 16 ms 284 KB Output is correct
9 Partially correct 112 ms 272 KB Output is partially correct
10 Partially correct 110 ms 292 KB Output is partially correct
11 Correct 33 ms 296 KB Output is correct
12 Partially correct 53 ms 308 KB Output is partially correct
13 Partially correct 52 ms 296 KB Output is partially correct
14 Partially correct 57 ms 300 KB Output is partially correct
15 Partially correct 68 ms 300 KB Output is partially correct
16 Partially correct 33 ms 336 KB Output is partially correct
17 Partially correct 68 ms 336 KB Output is partially correct
18 Partially correct 74 ms 260 KB Output is partially correct
19 Partially correct 102 ms 300 KB Output is partially correct
20 Partially correct 108 ms 304 KB Output is partially correct
21 Partially correct 127 ms 300 KB Output is partially correct
22 Partially correct 71 ms 308 KB Output is partially correct
23 Partially correct 146 ms 288 KB Output is partially correct
24 Partially correct 135 ms 304 KB Output is partially correct
25 Partially correct 114 ms 308 KB Output is partially correct
26 Correct 22 ms 304 KB Output is correct
27 Partially correct 133 ms 328 KB Output is partially correct
28 Partially correct 55 ms 300 KB Output is partially correct
29 Partially correct 102 ms 304 KB Output is partially correct
30 Partially correct 105 ms 300 KB Output is partially correct
31 Partially correct 91 ms 304 KB Output is partially correct
32 Partially correct 120 ms 312 KB Output is partially correct
33 Partially correct 109 ms 304 KB Output is partially correct
34 Partially correct 110 ms 300 KB Output is partially correct
35 Partially correct 128 ms 304 KB Output is partially correct
36 Partially correct 104 ms 296 KB Output is partially correct
37 Partially correct 139 ms 304 KB Output is partially correct
38 Partially correct 97 ms 304 KB Output is partially correct
39 Partially correct 151 ms 304 KB Output is partially correct
40 Partially correct 149 ms 208 KB Output is partially correct
41 Partially correct 127 ms 292 KB Output is partially correct
42 Partially correct 118 ms 292 KB Output is partially correct
43 Partially correct 24 ms 208 KB Output is partially correct
44 Partially correct 67 ms 336 KB Output is partially correct
45 Correct 25 ms 208 KB Output is correct
46 Partially correct 96 ms 284 KB Output is partially correct
47 Partially correct 63 ms 296 KB Output is partially correct
48 Partially correct 163 ms 300 KB Output is partially correct