QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#430060#4565. Rarest Insectsjames1BadCreeper#0 7ms4112kbC++171.7kb2024-06-03 12:53:272024-06-03 12:53:27

Judging History

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

  • [2024-06-03 12:53:27]
  • 评测
  • 测评结果:0
  • 用时:7ms
  • 内存:4112kb
  • [2024-06-03 12:53:27]
  • 提交

answer

#include "insects.h"
#include <bits/stdc++.h>
using namespace std; 
const int N = 2e3 + 5; 

// 最多问 3n 次询问
int n, m, k, id[N], cnt; 
vector<int> arr; 
bool in[N]; 
mt19937 Rand(time(0)); 

void Move_inside(int x) { move_inside(id[x] - 1); }
void Move_outside(int x) { move_outside(id[x] - 1); }
bool check(int x) { // 最罕见的昆虫是否能 >= x
    cnt = n; 
    for (int i : arr) {
        Move_inside(i); in[i] = 1; 
        if (press_button() > x) {
            Move_outside(i), in[i] = 0, --cnt; 
            if (cnt < k * x) {
                for (int i : arr)
                    if (in[i]) Move_outside(i), in[i] = 0; 
                return 0; 
            }
        }
    }
    if (cnt == k * x) {
        vector<int> newarr; 
        for (int i : arr)
            if (in[i]) newarr.emplace_back(i); 
        arr = newarr; 
    }
    return cnt == k * x; 
}
int min_cardinality(int N) {
    n = N; 
    k = n; 
    for (int i = 1; i <= n; ++i) id[i] = i; 
    shuffle(id + 1, id + n + 1, Rand);  
    for (int i = 1; i <= n; ++i) {
        Move_inside(i); 
        if (press_button() > 1) Move_outside(i), --k, arr.emplace_back(i); 
    }

    // 最罕见的出现次数是 1,当且仅当什么时候?
    int L = 0, R = n / k + 1; // [2, n / k]

    while (L + 1 != R) {
        int mid = L + R >> 1; 
        if (check(mid)) L = mid; 
        else R = mid; // 最罕见的昆虫一定 < mid
    }
    return L; 
}

// 我们可以知道的信息:

// n 次代价知道昆虫种类数 k
// n 次代价知道最常见的昆虫基数

// 那么最罕见的昆虫的基数至多是 n / k
// 直接扫,

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3724kb

input:

6
1
2
1
1
2
2
2
2
2

output:

8
0 5
8
2
8
0 4
8
2
8
1 4
8
0 0
8
2
8
0 1
8
2
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 2
8
2
8
1 2
8
0 3
8
2
8
1 3
8
3 2

result:

wrong answer Wrong answer.

Subtask #2:

score: 0
Wrong Answer

Test #24:

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

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 332
8
2
8
0 834
8
2
8
1 834
8
0 252
8
2
8
1 252
8
0 485
8
2
8
1 485
8
0 20
8
2
8
1 20
8
0 157
8
2
8
1 157
8
0 277
8
2
8
1 277
8
0 294
8
2
8
1 294
8
0 671
8
2
8
1 671
8
0 167
8
2
8
1 167
8
0 497
8
2
8
1 497
8
0 696
8
2
8
1 696
8
0 734
8
2
8
1 734
8
0 380
8
2
8
1 380
8
0 731
8
2
8
1 731
8
0 347
8
...

result:

wrong answer Wrong answer.

Subtask #3:

score: 0
Wrong Answer

Test #43:

score: 75
Accepted
time: 1ms
memory: 3828kb

input:

2
1
2
2

output:

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

result:

ok 

Test #44:

score: 75
Accepted
time: 1ms
memory: 3840kb

input:

2
1
1

output:

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

result:

ok 

Test #45:

score: 75
Accepted
time: 0ms
memory: 4068kb

input:

3
1
1
2
2

output:

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

result:

ok 

Test #46:

score: 75
Accepted
time: 1ms
memory: 4112kb

input:

6
1
2
2
2
1
2
2
3
3
3
2
2
2
2

output:

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

result:

ok 

Test #47:

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

input:

10
1
2
1
2
2
2
2
2
2
2
2
2
3
3
4
4
4
4
3
3
3
3

output:

8
0 5
8
2
8
0 4
8
2
8
1 4
8
0 7
8
2
8
0 1
8
2
8
1 1
8
0 9
8
2
8
1 9
8
0 3
8
2
8
1 3
8
0 6
8
2
8
1 6
8
0 0
8
2
8
1 0
8
0 2
8
2
8
1 2
8
0 8
8
2
8
1 8
8
0 4
8
2
8
0 1
8
2
8
0 9
8
2
8
0 3
8
2
8
0 6
8
2
8
1 6
8
0 0
8
2
8
1 0
8
0 2
8
2
8
1 2
8
0 8
8
2
8
1 8
8
0 4
8
2
8
0 1
8
2
8
0 9
8
2
8
0 3
8
2
8
3 3

result:

wrong answer Wrong answer.