답안 #1085495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085495 2024-09-08T10:38:58 Z SamueleVid 드문 곤충 (IOI22_insects) C++17
61.79 / 100
95 ms 1236 KB
#include <bits/stdc++.h>
using namespace std;
 
void move_inside(int i);
void move_outside(int i);
int press_button();
 
set<int> dentro;

vector<int> sol(vector<int> types, vector<int> usable) {
    // cout << "types : ";
    // for (auto x : types) cout << x << " ";
    // cout << '\n';
    // cout << "usable : ";
    // for (auto x : usable) cout << x << " ";
    // cout << '\n';
 
    vector<int> res;
    if (usable.size() == 0) {
        for (auto x : types) res.push_back(1);
        return res;
    }
    if (types.size() == 1) {
        res.push_back(usable.size() + 1);
        return res;
    }
    if (usable.back() < types[1]) {
        res.push_back(usable.size() + 1);
        for (int i = 1; i < types.size(); i ++) res.push_back(1);
        return res;
    }
    vector<int> sx, dx;
    
    for (auto i : usable) {
        if (i < types[types.size() / 2]) sx.push_back(i);
        else dx.push_back(i);
    }
 
    vector<int> types_sx, types_dx;
    for (int i = 0; i < types.size() / 2; i ++) types_sx.push_back(types[i]);
    for (int i = types.size() / 2; i < types.size(); i ++) types_dx.push_back(types[i]);
 
    // cout << "mezzo : " << types[types.size() / 2] << '\n';
    // cout << "dx : ";
    // for (auto x : dx) cout << x << " ";
    // cout << '\n'; 
    // cout << "type_dx : ";
    // for (auto x : types_dx) cout << x << " ";
    // cout << '\n'; 
 
    vector<int> pusha_sx = sx;
    vector<int> pusha_dx;

    // praticamente ne tolgo solo alcuni perché potrebbero essere già alcuni giusti
    set<int> types_dx_set;
    for (auto x : types_dx) types_dx_set.insert(x);
    vector<int> to_remove, to_add;
    
    for (auto x : dentro) {
        if (!types_dx_set.count(x)) {
            to_remove.push_back(x);
            move_outside(x);
        }
    }
    for (auto x : to_remove) dentro.erase(x);

    for (auto x : types_dx_set) {
        if (!dentro.count(x)) {
            to_add.push_back(x);
            move_inside(x);
        }
    }
    for (auto x : to_add) dentro.insert(x);
    // ora dentro ci sono solo quelli di types_dx
    
    for (auto x : dx) {
        move_inside(x);
        if (press_button() == 2) { // fa parte dei gruppi
            pusha_dx.push_back(x);
        }
        else { // == 1, è dei gruppi a sinistra
            pusha_sx.push_back(x);
        }
        move_outside(x);
    }
    // for (auto x : types_dx) move_outside(x);
 
    vector<int> res_dx = sol(types_dx, pusha_dx); // vado prima a destra per conservare alcuni in dentro
    vector<int> res_sx = sol(types_sx, pusha_sx);
    for (auto x : res_sx) res.push_back(x);
    for (auto x : res_dx) res.push_back(x);
 
    return res;
}
 
int min_cardinality(int N) {
    // il primo elemento di tutti i gruppi
    vector<int> types;
    for (int i = 0; i < N; i ++) {
        move_inside(i);
        if (press_button() > 1) {
            move_outside(i);
            continue;
        }
        types.push_back(i);
    }
    for (auto x : types) dentro.insert(x);
 
    set<int> types_set;
    for (auto x : types) types_set.insert(x);
 
    vector<int> usable;
    for (int i = 0; i < N; i ++) if (!types_set.count(i)) usable.push_back(i);
    vector<int> res = sol(types, usable);
 
    int minim = N;
    for (auto x : res) minim = min(minim, x);
 
    return minim;
}

Compilation message

insects.cpp: In function 'std::vector<int> sol(std::vector<int>, std::vector<int>)':
insects.cpp:20:19: warning: unused variable 'x' [-Wunused-variable]
   20 |         for (auto x : types) res.push_back(1);
      |                   ^
insects.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i = 1; i < types.size(); i ++) res.push_back(1);
      |                         ~~^~~~~~~~~~~~~~
insects.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < types.size() / 2; i ++) types_sx.push_back(types[i]);
      |                     ~~^~~~~~~~~~~~~~~~~~
insects.cpp:41:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = types.size() / 2; i < types.size(); i ++) types_dx.push_back(types[i]);
      |                                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 7 ms 432 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 4 ms 344 KB Output is correct
16 Correct 3 ms 444 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 4 ms 440 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 4 ms 344 KB Output is correct
22 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 7 ms 432 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 4 ms 344 KB Output is correct
16 Correct 3 ms 444 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 4 ms 440 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 4 ms 344 KB Output is correct
22 Correct 5 ms 344 KB Output is correct
23 Correct 4 ms 344 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 27 ms 692 KB Output is correct
26 Correct 33 ms 860 KB Output is correct
27 Correct 11 ms 848 KB Output is correct
28 Correct 36 ms 600 KB Output is correct
29 Correct 10 ms 344 KB Output is correct
30 Correct 23 ms 688 KB Output is correct
31 Correct 14 ms 472 KB Output is correct
32 Correct 21 ms 344 KB Output is correct
33 Correct 19 ms 592 KB Output is correct
34 Correct 26 ms 668 KB Output is correct
35 Correct 21 ms 700 KB Output is correct
36 Correct 30 ms 604 KB Output is correct
37 Correct 27 ms 440 KB Output is correct
38 Correct 29 ms 692 KB Output is correct
39 Correct 48 ms 856 KB Output is correct
40 Correct 40 ms 700 KB Output is correct
41 Correct 22 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 9 ms 440 KB Output is correct
8 Correct 12 ms 600 KB Output is correct
9 Partially correct 79 ms 668 KB Output is partially correct
10 Partially correct 77 ms 1236 KB Output is partially correct
11 Correct 16 ms 472 KB Output is correct
12 Partially correct 57 ms 856 KB Output is partially correct
13 Partially correct 29 ms 596 KB Output is partially correct
14 Partially correct 69 ms 724 KB Output is partially correct
15 Partially correct 48 ms 464 KB Output is partially correct
16 Partially correct 54 ms 592 KB Output is partially correct
17 Partially correct 65 ms 844 KB Output is partially correct
18 Partially correct 55 ms 968 KB Output is partially correct
19 Partially correct 54 ms 676 KB Output is partially correct
20 Partially correct 63 ms 604 KB Output is partially correct
21 Partially correct 70 ms 600 KB Output is partially correct
22 Partially correct 82 ms 712 KB Output is partially correct
23 Partially correct 95 ms 672 KB Output is partially correct
24 Partially correct 91 ms 796 KB Output is partially correct
25 Partially correct 71 ms 828 KB Output is partially correct
26 Partially correct 64 ms 680 KB Output is partially correct
27 Partially correct 76 ms 468 KB Output is partially correct
28 Partially correct 67 ms 720 KB Output is partially correct
29 Partially correct 65 ms 732 KB Output is partially correct
30 Partially correct 70 ms 668 KB Output is partially correct
31 Partially correct 63 ms 732 KB Output is partially correct
32 Partially correct 72 ms 716 KB Output is partially correct
33 Partially correct 70 ms 728 KB Output is partially correct
34 Partially correct 90 ms 724 KB Output is partially correct
35 Partially correct 74 ms 672 KB Output is partially correct
36 Partially correct 67 ms 480 KB Output is partially correct
37 Partially correct 85 ms 648 KB Output is partially correct
38 Partially correct 73 ms 944 KB Output is partially correct
39 Partially correct 95 ms 728 KB Output is partially correct
40 Partially correct 85 ms 592 KB Output is partially correct
41 Partially correct 70 ms 724 KB Output is partially correct
42 Partially correct 86 ms 592 KB Output is partially correct
43 Partially correct 9 ms 600 KB Output is partially correct
44 Partially correct 24 ms 496 KB Output is partially correct
45 Correct 15 ms 428 KB Output is correct
46 Correct 8 ms 688 KB Output is correct
47 Partially correct 80 ms 844 KB Output is partially correct
48 Partially correct 43 ms 696 KB Output is partially correct