# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
635484 | 2022-08-26T10:26:28 Z | TheLostCookie | Rarest Insects (IOI22_insects) | C++17 | 71 ms | 428 KB |
#include <bits/stdc++.h> #include "insects.h" using namespace std; typedef vector<int> vi; #define FOR(i,a,b) for(int i = (a); i<(b); ++i) #define all(v) begin(v),end(v) #define pb push_back int min_cardinality(int N) { vi types; vi currSet(N); iota(all(currSet),0); int ans = 0; vi nextSet; FOR(i,0,currSet.size()) { int c = currSet[i]; move_inside(c); if(press_button() > 1) { move_outside(c); nextSet.pb(c); } else { types.pb(c); } } FOR(i,0,types.size()) { int c = types[i]; move_outside(c); } currSet.swap(nextSet); ans++; int t = types.size(); assert(currSet.size() == N-t); vector<int> dp(N-t+1,(1<<30)); vector<int> argMin(N-t+1,-1); FOR(i,0,min(t,N-t+1)) { dp[i] = 0; argMin[i] = 0; } FOR(i,t,min(2*t,N-t+1)) { dp[i] = i; argMin[i] = t; } FOR(i,2*t,min(3*t,N-t+1)) { dp[i] = i+t; argMin[i] = 2*t; } FOR(i,3*t,N-t+1) { int top = i-t, bot = t; while(top > 0) { int choice = i+max(dp[bot-1]-argMin[bot-1]/t,dp[top]); if(choice <= dp[i]) { dp[i] = choice; argMin[i] = bot; } top -= t, bot += t; } } FOR(i,0,N-t+1) assert(dp[i] <= 2*N); bool currSetInside = false; while(!currSet.empty()) { if(currSet.size() < t) { currSet.clear(); } else { vi top, bot; int m = currSet.size(); if(currSetInside) { FOR(i,0,argMin[m]/t) { int c = currSet[i]; bot.pb(c); } FOR(i,argMin[m]/t,m) { int c = currSet[i]; move_outside(c); } } FOR(i,(currSetInside?(argMin[m]/t):(0)),m) { int c = currSet[i]; move_inside(c); if(press_button() > argMin[m]/t) { move_outside(c); top.pb(c); } else { bot.pb(c); } } assert(top.size() + bot.size() == m); assert(bot.size() <= argMin[m]); if(bot.size() == argMin[m]) { currSet.swap(top); ans += argMin[m]/t; FOR(i,0,bot.size()) { move_outside(bot[i]); } currSetInside = false; } else { if(m < 2*t || m >= 3*t) { currSet.swap(bot); currSetInside = true; } else { assert(argMin[m] == 2*t); //Microoptimization for 2*t <= n < 3*t int twos = 0; FOR(i,0,t) { move_inside(types[i]); if(press_button() > 2) { twos++; } move_outside(types[i]); } if(twos+t == bot.size()) { ans++; } else { assert(twos > bot.size()%t); } currSet.clear(); } } } } return ans; }
Compilation message
# | 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 | 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 | 3 ms | 208 KB | Output is correct |
7 | Correct | 2 ms | 208 KB | Output is correct |
8 | Correct | 6 ms | 208 KB | Output is correct |
9 | Correct | 4 ms | 208 KB | Output is correct |
10 | Correct | 4 ms | 208 KB | Output is correct |
11 | Correct | 2 ms | 208 KB | Output is correct |
12 | Correct | 6 ms | 304 KB | Output is correct |
13 | Correct | 6 ms | 300 KB | Output is correct |
14 | Correct | 6 ms | 208 KB | Output is correct |
15 | Correct | 5 ms | 208 KB | Output is correct |
16 | Correct | 5 ms | 208 KB | Output is correct |
17 | Correct | 3 ms | 208 KB | Output is correct |
18 | Correct | 4 ms | 208 KB | Output is correct |
19 | Correct | 4 ms | 208 KB | Output is correct |
20 | Correct | 4 ms | 208 KB | Output is correct |
21 | Correct | 3 ms | 208 KB | Output is correct |
22 | Correct | 2 ms | 208 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 | 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 | 3 ms | 208 KB | Output is correct |
7 | Correct | 2 ms | 208 KB | Output is correct |
8 | Correct | 6 ms | 208 KB | Output is correct |
9 | Correct | 4 ms | 208 KB | Output is correct |
10 | Correct | 4 ms | 208 KB | Output is correct |
11 | Correct | 2 ms | 208 KB | Output is correct |
12 | Correct | 6 ms | 304 KB | Output is correct |
13 | Correct | 6 ms | 300 KB | Output is correct |
14 | Correct | 6 ms | 208 KB | Output is correct |
15 | Correct | 5 ms | 208 KB | Output is correct |
16 | Correct | 5 ms | 208 KB | Output is correct |
17 | Correct | 3 ms | 208 KB | Output is correct |
18 | Correct | 4 ms | 208 KB | Output is correct |
19 | Correct | 4 ms | 208 KB | Output is correct |
20 | Correct | 4 ms | 208 KB | Output is correct |
21 | Correct | 3 ms | 208 KB | Output is correct |
22 | Correct | 2 ms | 208 KB | Output is correct |
23 | Correct | 23 ms | 300 KB | Output is correct |
24 | Correct | 9 ms | 300 KB | Output is correct |
25 | Correct | 18 ms | 308 KB | Output is correct |
26 | Correct | 28 ms | 208 KB | Output is correct |
27 | Correct | 19 ms | 304 KB | Output is correct |
28 | Correct | 9 ms | 208 KB | Output is correct |
29 | Correct | 20 ms | 208 KB | Output is correct |
30 | Correct | 28 ms | 288 KB | Output is correct |
31 | Correct | 30 ms | 312 KB | Output is correct |
32 | Correct | 24 ms | 308 KB | Output is correct |
33 | Correct | 30 ms | 208 KB | Output is correct |
34 | Correct | 27 ms | 208 KB | Output is correct |
35 | Correct | 19 ms | 304 KB | Output is correct |
36 | Correct | 28 ms | 208 KB | Output is correct |
37 | Correct | 29 ms | 208 KB | Output is correct |
38 | Correct | 23 ms | 304 KB | Output is correct |
39 | Correct | 16 ms | 208 KB | Output is correct |
40 | Correct | 14 ms | 208 KB | Output is correct |
41 | Correct | 12 ms | 208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 208 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 | 1 ms | 316 KB | Output is correct |
7 | Correct | 60 ms | 328 KB | Output is correct |
8 | Correct | 21 ms | 312 KB | Output is correct |
9 | Correct | 51 ms | 428 KB | Output is correct |
10 | Correct | 41 ms | 316 KB | Output is correct |
11 | Correct | 42 ms | 312 KB | Output is correct |
12 | Correct | 18 ms | 312 KB | Output is correct |
13 | Correct | 40 ms | 332 KB | Output is correct |
14 | Correct | 56 ms | 312 KB | Output is correct |
15 | Correct | 44 ms | 336 KB | Output is correct |
16 | Correct | 55 ms | 304 KB | Output is correct |
17 | Correct | 56 ms | 324 KB | Output is correct |
18 | Correct | 50 ms | 300 KB | Output is correct |
19 | Correct | 44 ms | 320 KB | Output is correct |
20 | Correct | 42 ms | 316 KB | Output is correct |
21 | Correct | 47 ms | 320 KB | Output is correct |
22 | Correct | 29 ms | 424 KB | Output is correct |
23 | Correct | 49 ms | 292 KB | Output is correct |
24 | Correct | 40 ms | 316 KB | Output is correct |
25 | Correct | 22 ms | 308 KB | Output is correct |
26 | Correct | 14 ms | 312 KB | Output is correct |
27 | Correct | 71 ms | 320 KB | Output is correct |
28 | Correct | 61 ms | 300 KB | Output is correct |
29 | Correct | 59 ms | 328 KB | Output is correct |
30 | Correct | 57 ms | 324 KB | Output is correct |
31 | Correct | 23 ms | 316 KB | Output is correct |
32 | Correct | 31 ms | 304 KB | Output is correct |
33 | Correct | 44 ms | 208 KB | Output is correct |
34 | Correct | 45 ms | 300 KB | Output is correct |
35 | Correct | 48 ms | 316 KB | Output is correct |
36 | Correct | 54 ms | 324 KB | Output is correct |
37 | Correct | 52 ms | 336 KB | Output is correct |
38 | Correct | 44 ms | 328 KB | Output is correct |
39 | Correct | 46 ms | 324 KB | Output is correct |
40 | Correct | 40 ms | 428 KB | Output is correct |
41 | Correct | 49 ms | 316 KB | Output is correct |
42 | Correct | 46 ms | 304 KB | Output is correct |
43 | Correct | 6 ms | 308 KB | Output is correct |
44 | Correct | 25 ms | 304 KB | Output is correct |
45 | Correct | 66 ms | 308 KB | Output is correct |
46 | Correct | 20 ms | 304 KB | Output is correct |
47 | Correct | 31 ms | 208 KB | Output is correct |
48 | Correct | 13 ms | 308 KB | Output is correct |