답안 #1055596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055596 2024-08-12T23:18:34 Z Trent 버섯 세기 (IOI20_mushrooms) C++17
43.1298 / 100
18 ms 2644 KB
#include "mushrooms.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
typedef vector<ll> vll;
typedef set<int> si;

int count_mushrooms(int n) {
	int IVL = 120;
	vi chk;
	for(int i = 0; i < n; i += IVL) chk.push_back(i);
	if(chk.back() < n-1) chk.push_back(n-1);
	vi ty(chk.size());
	ty[0] = 0;
	REP(i, 1, chk.size()) {
		vi tst = {0, chk[i]};
		ty[i] = use_machine(tst) == 0 ? 0 : 1;
	}

	vi ac, bc;
	forR(i, chk.size()) {
		if(ty[i] == 0) ac.push_back(chk[i]);
		else bc.push_back(chk[i]);
	}
	vb usd(n, false);
	for(int i : chk) usd[i] = true;
	vector<si> ai(ac.size()), bi(bc.size());
	forR(i, (int) ac.size() - 1) for(int j = ac[i] + 1; j < ac[i+1]; ++j) if(!usd[j]) ai[i].insert(j);
	forR(i, (int) bc.size() - 1) for(int j = bc[i] + 1; j < bc[i+1]; ++j) if(!usd[j]) bi[i].insert(j);
	vi ain(n, -1), bin(n, -1);
	forR(i, ai.size()) for(int j : ai[i]) ain[j] = i;
	forR(i, bi.size()) for(int j : bi[i]) bin[j] = i;

	si ane, bne;
	forR(i, ai.size()) if(!ai[i].empty()) ane.insert(i);
	forR(i, bi.size()) if(!bi[i].empty()) bne.insert(i);
	int tot = (int) ac.size();
	while(!ane.empty() || !bne.empty()){
		si qus;
		if(ane.size() >= bne.size()) {
			for(int i : ane) {
				qus.insert(ac[i]);
				qus.insert(ac[i+1]);
				qus.insert(*ai[i].begin());
			}
			vi qu;
			for(int i : qus) qu.push_back(i);
			int res = use_machine(qu);
			cerr << qu.size() << ' ' << res << '\n';
			tot += (int) ane.size() - res / 2;
		} else {
			for(int i : bne) {
				qus.insert(bc[i]);
				qus.insert(bc[i+1]);
				qus.insert(*bi[i].begin());
			}
			vi qu;
			for(int i : qus) qu.push_back(i);
			int res = use_machine(qu);
			cerr << qu.size() << ' ' << res << '\n';
			tot += res / 2;
		}
		for(int i : qus) {
			if(!usd[i]) {
				usd[i] = true;
				if(ain[i] != -1) {
					ai[ain[i]].erase(i);
					if(ai[ain[i]].empty()) ane.erase(ain[i]);
				}
				if(bin[i] != -1) {
					bi[bin[i]].erase(i);
					if(bi[bin[i]].empty()) bne.erase(bin[i]);
				}
			}
		}
	}
	forR(i, n) if(!usd[i]) {
		tot += use_machine({0, i}) == 0 ? 1 : 0;
	}
	return tot;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
      |                                         ^
mushrooms.cpp:20:2: note: in expansion of macro 'REP'
   20 |  REP(i, 1, chk.size()) {
      |  ^~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:26:2: note: in expansion of macro 'forR'
   26 |  forR(i, chk.size()) {
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:36:2: note: in expansion of macro 'forR'
   36 |  forR(i, ai.size()) for(int j : ai[i]) ain[j] = i;
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:37:2: note: in expansion of macro 'forR'
   37 |  forR(i, bi.size()) for(int j : bi[i]) bin[j] = i;
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:40:2: note: in expansion of macro 'forR'
   40 |  forR(i, ai.size()) if(!ai[i].empty()) ane.insert(i);
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:41:2: note: in expansion of macro 'forR'
   41 |  forR(i, bi.size()) if(!bi[i].empty()) bne.insert(i);
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 444 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Partially correct 3 ms 600 KB Output is partially correct
7 Partially correct 11 ms 1368 KB Output is partially correct
8 Partially correct 13 ms 2136 KB Output is partially correct
9 Partially correct 12 ms 2136 KB Output is partially correct
10 Partially correct 15 ms 2644 KB Output is partially correct
11 Partially correct 15 ms 2392 KB Output is partially correct
12 Partially correct 14 ms 2304 KB Output is partially correct
13 Partially correct 14 ms 2392 KB Output is partially correct
14 Partially correct 7 ms 1368 KB Output is partially correct
15 Partially correct 14 ms 2444 KB Output is partially correct
16 Partially correct 15 ms 2392 KB Output is partially correct
17 Partially correct 8 ms 1368 KB Output is partially correct
18 Partially correct 17 ms 2392 KB Output is partially correct
19 Partially correct 13 ms 2392 KB Output is partially correct
20 Partially correct 14 ms 2392 KB Output is partially correct
21 Partially correct 14 ms 2392 KB Output is partially correct
22 Partially correct 13 ms 2480 KB Output is partially correct
23 Partially correct 13 ms 2392 KB Output is partially correct
24 Partially correct 7 ms 1368 KB Output is partially correct
25 Partially correct 14 ms 2468 KB Output is partially correct
26 Partially correct 12 ms 2392 KB Output is partially correct
27 Partially correct 14 ms 2392 KB Output is partially correct
28 Partially correct 12 ms 2392 KB Output is partially correct
29 Partially correct 12 ms 2392 KB Output is partially correct
30 Partially correct 14 ms 2392 KB Output is partially correct
31 Partially correct 12 ms 2392 KB Output is partially correct
32 Partially correct 18 ms 2240 KB Output is partially correct
33 Partially correct 16 ms 2392 KB Output is partially correct
34 Partially correct 12 ms 2392 KB Output is partially correct
35 Partially correct 12 ms 2392 KB Output is partially correct
36 Partially correct 12 ms 2392 KB Output is partially correct
37 Partially correct 12 ms 2392 KB Output is partially correct
38 Partially correct 11 ms 2392 KB Output is partially correct
39 Partially correct 12 ms 2392 KB Output is partially correct
40 Partially correct 12 ms 2392 KB Output is partially correct
41 Partially correct 12 ms 2392 KB Output is partially correct
42 Partially correct 12 ms 2392 KB Output is partially correct
43 Partially correct 12 ms 2392 KB Output is partially correct
44 Partially correct 12 ms 2392 KB Output is partially correct
45 Partially correct 12 ms 2392 KB Output is partially correct
46 Partially correct 12 ms 2392 KB Output is partially correct
47 Partially correct 12 ms 2392 KB Output is partially correct
48 Partially correct 13 ms 2392 KB Output is partially correct
49 Partially correct 14 ms 2236 KB Output is partially correct
50 Partially correct 12 ms 2392 KB Output is partially correct
51 Partially correct 12 ms 2392 KB Output is partially correct
52 Partially correct 12 ms 2392 KB Output is partially correct
53 Partially correct 12 ms 2392 KB Output is partially correct
54 Partially correct 17 ms 2392 KB Output is partially correct
55 Partially correct 18 ms 2392 KB Output is partially correct
56 Partially correct 12 ms 2392 KB Output is partially correct
57 Partially correct 12 ms 2392 KB Output is partially correct
58 Partially correct 14 ms 2392 KB Output is partially correct
59 Partially correct 12 ms 2348 KB Output is partially correct
60 Partially correct 12 ms 2392 KB Output is partially correct
61 Partially correct 12 ms 2392 KB Output is partially correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 0 ms 344 KB Output is correct
77 Correct 0 ms 344 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 0 ms 344 KB Output is correct
81 Correct 0 ms 344 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 344 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 0 ms 344 KB Output is correct
86 Correct 0 ms 344 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 0 ms 344 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct