QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#149164#4565. Rarest Insectsmohos_risitas0 7ms3860kbC++142.1kb2023-08-24 04:01:072023-08-24 04:01:07

Judging History

你现在查看的是最新测评结果

  • [2023-08-24 04:01:07]
  • 评测
  • 测评结果:0
  • 用时:7ms
  • 内存:3860kb
  • [2023-08-24 04:01:07]
  • 提交

answer

#include <iostream>
#include <vector>
#include <unordered_set>
#include <limits>
#include <set>
using namespace std;

void move_inside(int i);
void move_outside(int i);
int press_button();

set<int> get_representatives(int insect_count) {
    set<int> out;
    for (int i = 0; i < insect_count; ++i) {
        move_inside(i);
        if (press_button() == 1) {
            out.insert(i);
        } else {
            move_outside(i);
        }
    }

    for (int representative : out) {
        move_outside(representative);
    }
    return out;
}

int min_cardinality(int insect_count) {
    // press button, move inside, and move outside insect_count times
    set<int> representatives = get_representatives(insect_count);
   
    vector<unordered_set<int>> equivalence_tree;
    equivalence_tree.resize(2 * insect_count);

    // populate tree
    //      add non-representatives
    for (int i = 0; i < insect_count; ++i) {
        if (representatives.find(i) == representatives.end()) {
            equivalence_tree[1].insert(i);
        }
    }

    //      find child nodes
    for (int i = 2; i < equivalence_tree.size(); ++i) {
        unordered_set<int> &parent = equivalence_tree[i / 2];
       
        vector<int> cleanup_list;
        auto cursor = representatives.begin();
        for (int j = 0; j < representatives.size() / 2; ++j) {
            move_inside(*cursor);
            cleanup_list.push_back(*cursor);
            ++cursor;
        }
        for (int candidate : parent) {
            move_inside(candidate);
            if (press_button() == 2) {
                // candidate belongs to this node
                equivalence_tree[i].insert(candidate);
            }
            move_outside(candidate);
        }
        for (int litter : cleanup_list) {
            move_outside(litter);
        }
    }

    int minimum = numeric_limits<int>::max();
    for (int i = 1; i <= 4; ++i) {
        int cardinality = equivalence_tree[equivalence_tree.size() - i].size();
        if (cardinality < minimum) {
            minimum = cardinality;
        }
    }

    return minimum;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 1ms
memory: 3700kb

input:

6
1
1
1
2
2
2
1
1
2
1
1
2
2
2
2
2
2
2
2
2

output:

8
0 0
8
2
8
0 1
8
2
8
0 2
8
2
8
0 3
8
2
8
1 3
8
0 4
8
2
8
1 4
8
0 5
8
2
8
1 5
8
1 0
8
1 1
8
1 2
8
0 0
8
0 5
8
2
8
1 5
8
0 4
8
2
8
1 4
8
0 3
8
2
8
1 3
8
1 0
8
0 0
8
0 5
8
2
8
1 5
8
0 4
8
2
8
1 4
8
0 3
8
2
8
1 3
8
1 0
8
0 0
8
0 3
8
2
8
1 3
8
1 0
8
0 0
8
0 3
8
2
8
1 3
8
1 0
8
0 0
8
0 3
8
2
8
1 3
8
1 0
...

result:

ok 

Test #2:

score: -10
Wrong Answer
time: 1ms
memory: 3828kb

input:

2
1
2
1
1

output:

8
0 0
8
2
8
0 1
8
2
8
1 1
8
1 0
8
0 1
8
2
8
1 1
8
0 1
8
2
8
1 1
8
3 0

result:

wrong answer Wrong answer.

Subtask #2:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 7ms
memory: 3860kb

input:

1000
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2...

output:

8
0 0
8
2
8
0 1
8
2
8
1 1
8
0 2
8
2
8
1 2
8
0 3
8
2
8
1 3
8
0 4
8
2
8
1 4
8
0 5
8
2
8
1 5
8
0 6
8
2
8
1 6
8
0 7
8
2
8
1 7
8
0 8
8
2
8
1 8
8
0 9
8
2
8
1 9
8
0 10
8
2
8
1 10
8
0 11
8
2
8
1 11
8
0 12
8
2
8
1 12
8
0 13
8
2
8
1 13
8
0 14
8
2
8
1 14
8
0 15
8
2
8
1 15
8
0 16
8
2
8
1 16
8
0 17
8
2
8
1 17
8
...

result:

wrong answer Wrong answer.

Subtask #3:

score: 0
Wrong Answer

Test #43:

score: 0
Wrong Answer
time: 1ms
memory: 3696kb

input:

2
1
2
1
1

output:

8
0 0
8
2
8
0 1
8
2
8
1 1
8
1 0
8
0 1
8
2
8
1 1
8
0 1
8
2
8
1 1
8
3 0

result:

wrong answer Wrong answer.