Submission #631795

# Submission time Handle Problem Language Result Execution time Memory
631795 2022-08-18T18:57:33 Z garam1732 Rarest Insects (IOI22_insects) C++17
100 / 100
64 ms 632 KB
#include "insects.h"
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <algorithm>
#include <cassert>
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pi;

//vector<int> ans;
//stack<pi> S, v;
vector<int> v, w, u[2020];
vector<pi> p;
set<pi> s;
int d[2020];

int min_cardinality(int N) {
    int num = 0;
    for(int i = 0; i < N; i++) {
        move_inside(i);
        num++;
        if(i == 0) continue;
        if(press_button() > 1) {
            move_outside(i);
            num--;
            s.insert(pi(2, i));
        }
    }

    if(num == 1) return N;
    if(num == 2) {
        for(pi i : s) move_inside(i.ss);
        int mx = press_button();
        return N-mx;
    }

    //cout<<num<<endl;
    int sum = num;
    int lb = 1, ub = N/num, mid;
    while(lb < ub) {
        mid = (lb*5+ub*7+11)/12;
        for(pi i : s) {
            move_inside(i.ss);
            int x = press_button();
            if(x > mid) {
                w.push_back(i.ss);
                move_outside(i.ss);
                d[i.ss] = mid+1;
                p.push_back(pi(d[i.ss], i.ss));
                continue;
            }
            u[x].push_back(i.ss);
            d[i.ss] = x;
            p.push_back(pi(x, i.ss));
            sum++;
        }

        s.clear();
        for(pi t : p) s.insert(t);
        p.clear();

        bool flag = false;
        while(lb < ub) {
            mid = (lb*5+ub*7+11)/12;

//            for(int i = lb; i <= ub+1; i++) {
//                cout<<i<<" : ";
//                for(int t:u[i])cout<<t<<" ";
//                cout<<endl;
//            }
//            cout<<endl;
            if(flag) {
                for(int i = ub+1; i > mid; i--) {
                    for(int t : u[i]) {
                        move_outside(t);
                        sum--;
                    }
                }

                //assert(press_button() == mid);
                for(int i = mid+1; i <= ub+1; i++) {
                    w.push_back(u[i][0]);
                    for(int j = 1; j < u[i].size(); j++) {
                        int t = u[i][j];
                        move_inside(t);
                        if(press_button() > mid) {
                            move_outside(t);
                            w.push_back(t);
                        }
                        else {
                            sum++;
                            u[mid].push_back(t);
                            p.push_back(pi(d[t], t));
                        }
                    }
                }

                for(pi t : p) {
                    s.erase(t);
                    d[t.ss] = mid;
                    s.insert(pi(d[t.ss], t.ss));
                }
                p.clear();
            }
            flag = true;
            //cout<<sum<<endl;

            if(sum == mid*num) {
                for(int i = lb+1; i <= mid; i++)
                    for(int t : u[i])
                        s.erase(pi(d[t], t));
                for(int i = lb+1; i <= ub+1; i++) u[i].clear();
                lb = mid;
                w.clear();
                break;
            }
            else {
                for(int t : w) s.erase(pi(d[t], t));
//                for(int t : u[mid]) move_outside(t);
//                sum -= u[mid].size();
                for(int i = mid+1; i <= ub+1; i++) u[i].clear();
                w.clear();
                ub = mid-1;
            }
        }
    }

    return lb;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:86:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |                     for(int j = 1; j < u[i].size(); j++) {
      |                                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 6 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 4 ms 336 KB Output is correct
12 Correct 5 ms 336 KB Output is correct
13 Correct 6 ms 360 KB Output is correct
14 Correct 6 ms 360 KB Output is correct
15 Correct 5 ms 364 KB Output is correct
16 Correct 5 ms 336 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 5 ms 360 KB Output is correct
19 Correct 5 ms 352 KB Output is correct
20 Correct 6 ms 360 KB Output is correct
21 Correct 3 ms 352 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 6 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 4 ms 336 KB Output is correct
12 Correct 5 ms 336 KB Output is correct
13 Correct 6 ms 360 KB Output is correct
14 Correct 6 ms 360 KB Output is correct
15 Correct 5 ms 364 KB Output is correct
16 Correct 5 ms 336 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 5 ms 360 KB Output is correct
19 Correct 5 ms 352 KB Output is correct
20 Correct 6 ms 360 KB Output is correct
21 Correct 3 ms 352 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 15 ms 364 KB Output is correct
24 Correct 13 ms 336 KB Output is correct
25 Correct 26 ms 396 KB Output is correct
26 Correct 33 ms 384 KB Output is correct
27 Correct 11 ms 500 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 26 ms 388 KB Output is correct
30 Correct 23 ms 388 KB Output is correct
31 Correct 26 ms 372 KB Output is correct
32 Correct 25 ms 480 KB Output is correct
33 Correct 30 ms 396 KB Output is correct
34 Correct 27 ms 372 KB Output is correct
35 Correct 20 ms 384 KB Output is correct
36 Correct 21 ms 600 KB Output is correct
37 Correct 19 ms 508 KB Output is correct
38 Correct 24 ms 368 KB Output is correct
39 Correct 28 ms 336 KB Output is correct
40 Correct 17 ms 348 KB Output is correct
41 Correct 9 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 25 ms 392 KB Output is correct
8 Correct 17 ms 336 KB Output is correct
9 Correct 56 ms 384 KB Output is correct
10 Correct 47 ms 420 KB Output is correct
11 Correct 16 ms 392 KB Output is correct
12 Correct 30 ms 336 KB Output is correct
13 Correct 47 ms 364 KB Output is correct
14 Correct 60 ms 456 KB Output is correct
15 Correct 44 ms 460 KB Output is correct
16 Correct 44 ms 540 KB Output is correct
17 Correct 58 ms 500 KB Output is correct
18 Correct 45 ms 400 KB Output is correct
19 Correct 41 ms 372 KB Output is correct
20 Correct 50 ms 396 KB Output is correct
21 Correct 36 ms 632 KB Output is correct
22 Correct 64 ms 404 KB Output is correct
23 Correct 61 ms 372 KB Output is correct
24 Correct 36 ms 436 KB Output is correct
25 Correct 32 ms 504 KB Output is correct
26 Correct 16 ms 352 KB Output is correct
27 Correct 43 ms 444 KB Output is correct
28 Correct 47 ms 412 KB Output is correct
29 Correct 41 ms 384 KB Output is correct
30 Correct 38 ms 456 KB Output is correct
31 Correct 37 ms 364 KB Output is correct
32 Correct 58 ms 388 KB Output is correct
33 Correct 37 ms 372 KB Output is correct
34 Correct 43 ms 368 KB Output is correct
35 Correct 53 ms 444 KB Output is correct
36 Correct 38 ms 376 KB Output is correct
37 Correct 38 ms 384 KB Output is correct
38 Correct 37 ms 372 KB Output is correct
39 Correct 42 ms 336 KB Output is correct
40 Correct 45 ms 476 KB Output is correct
41 Correct 51 ms 440 KB Output is correct
42 Correct 40 ms 456 KB Output is correct
43 Correct 12 ms 336 KB Output is correct
44 Correct 32 ms 372 KB Output is correct
45 Correct 17 ms 336 KB Output is correct
46 Correct 13 ms 404 KB Output is correct
47 Correct 30 ms 344 KB Output is correct
48 Correct 28 ms 372 KB Output is correct