QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140499#4565. Rarest Insectssomethingnew#0 4ms3888kbC++204.6kb2023-08-16 00:49:212024-07-04 01:45:16

Judging History

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

  • [2024-07-04 01:45:16]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:3888kb
  • [2023-08-16 00:49:21]
  • 提交

answer

//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "random"
#define all(x) x.begin(), x.end()
using namespace std;
#include "insects.h"
mt19937 rnd;
int min_cardinality(int N) {
    vector<int> iba(N);
    for (int i = 0; i < N; ++i) {
        iba[i] = i;
    }
    vector<int> ex(N);
    int timka = 1;
    for (int i = 0; i < N; ++i) {
        swap(iba[i], iba[rnd() % N]);
    }
    int cnt = 0;
    int gcnt = 0;
    int prvl = 3;
    int lstch = 0;
    for (int i = 0; i < N; ++i) {
        move_inside(iba[i]);
        if (press_button() == 2) {
            move_outside(iba[i]);
        } else {
            cnt++;
            lstch = i;
            //cerr << "ADD " << i << ' ' << press_button() << endl;
            ex[i] = timka;
        }
    }
    timka++;
    gcnt = cnt * 2;
    cnt = gcnt;
    for (int i = (lstch + 1) % N; i != lstch; i = (i + 1) % N) {
        //cerr << i << endl;
        if (ex[i] == 0) {
            //cerr << i << endl;
            move_inside(iba[i]);
            if (prvl < press_button()) {
                move_outside(iba[i]);
            } else {
                ex[i] = timka;
                cnt--;
                lstch = i;
                if (cnt == 0) {
                    timka++;
                    cnt = gcnt;
                    prvl += 2;
                }
            }
        }
    }
    cnt = gcnt / 2;
    prvl--;
    for (int i = 0; i < N; ++i) {
        if (ex[i] == timka) {
            //cout << i << endl;
            move_outside(iba[i]);

        }
    }
    for (int i = 0; i < N; ++i) {
        if (ex[i] == timka) {
            //cerr << i << endl;
            move_inside(iba[i]);
            if (prvl != press_button()) {
                move_outside(iba[i]);
            } else {
                ex[i] = timka;
                cnt--;
                if (cnt == 0) {
                    prvl++;
                    break;
                }
            }
        }
    }
    return prvl - 1;
}
#ifdef __APPLE__

static inline constexpr int kMaxQueries = 40000;

static int N;
// Insect types are compressed to colors in the range [0, N).
static std::vector<int> color;
static std::vector<bool> in_box;

static std::vector<int> color_occurrences;
static std::multiset<int> max_occurrences;

static std::vector<int> op_counter(3, 0);

static inline void protocol_violation(std::string message) {
    printf("Protocol Violation: %s\n", message.c_str());
    exit(0);
}

void move_inside(int i) {
    if (i < 0 || i >= N) {
        protocol_violation("invalid parameter");
    }
    ++op_counter[0];
    if (op_counter[0] > kMaxQueries) {
        protocol_violation("too many calls");
    }
    if (!in_box[i]) {
        in_box[i] = true;
        max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
        ++color_occurrences[color[i]];
        max_occurrences.insert(color_occurrences[color[i]]);
    }
}

void move_outside(int i) {
    if (i < 0 || i >= N) {
        protocol_violation("invalid parameter");
    }
    ++op_counter[1];
    if (op_counter[1] > kMaxQueries) {
        protocol_violation("too many calls");
    }
    if (in_box[i]) {
        in_box[i] = false;
        max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
        --color_occurrences[color[i]];
        max_occurrences.insert(color_occurrences[color[i]]);
    }
}

int press_button() {
    ++op_counter[2];
    if (op_counter[2] > kMaxQueries) {
        protocol_violation("too many calls");
    }
    return *(max_occurrences.rbegin());
}

int main() {
    N=2000;//assert(1 == scanf("%d", &N));
    color.resize(N);
    in_box.assign(N, false);

    std::map<int, int> type_to_color;
    for (int i = 0; i < N; ++i) {
        int Ti;
        Ti = i % 6 + 1;
        //assert(1 == scanf("%d", &Ti));
        if (type_to_color.find(Ti) == type_to_color.end()) {
            int new_color = type_to_color.size();
            type_to_color[Ti] = new_color;
            max_occurrences.insert(0);
        }
        color[i] = type_to_color[Ti];
    }

    color_occurrences.assign(type_to_color.size(), 0);

    int answer = min_cardinality(N);
    int Q = *std::max_element(op_counter.begin(), op_counter.end());
    printf("%d\n", answer);
    printf("%d\n", Q);
    return 0;
}
#endif

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Interactor Judgement Failed

Test #1:

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

input:

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

output:

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

result:

ok 

Test #2:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

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

result:

ok 

Test #3:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

2
1
1

output:

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

result:

ok 

Test #4:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

3
1
2
1
2
2

output:

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

result:

ok 

Test #5:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

5
1
2
2
1
2
2
2
3
2
3
2

output:

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

result:

ok 

Test #6:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

8
1
2
2
1
2
2
1
2
2
3
4
3
4
4
2
2
3

output:

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

result:

ok 

Test #7:

score: 0
Accepted
time: 3ms
memory: 3804kb

input:

199
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 19
8
2
8
0 68
8
2
8
1 68
8
0 92
8
2
8
1 92
8
0 49
8
2
8
1 49
8
0 184
8
2
8
1 184
8
0 62
8
2
8
1 62
8
0 191
8
2
8
1 191
8
0 107
8
2
8
1 107
8
0 149
8
2
8
1 149
8
0 88
8
2
8
1 88
8
0 21
8
2
8
1 21
8
0 152
8
2
8
1 152
8
0 97
8
2
8
1 97
8
0 27
8
2
8
1 27
8
0 75
8
2
8
1 75
8
0 29
8
2
8
1 29
8
0 114
8...

result:

ok 

Test #8:

score: 0
Accepted
time: 2ms
memory: 3804kb

input:

200
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

8
0 86
8
2
8
0 174
8
2
8
0 134
8
2
8
0 159
8
2
8
0 17
8
2
8
0 139
8
2
8
0 87
8
2
8
0 3
8
2
8
0 69
8
2
8
0 189
8
2
8
0 38
8
2
8
0 165
8
2
8
0 192
8
2
8
0 26
8
2
8
0 39
8
2
8
0 199
8
2
8
0 119
8
2
8
0 4
8
2
8
0 36
8
2
8
0 106
8
2
8
0 132
8
2
8
0 20
8
2
8
0 54
8
2
8
0 14
8
2
8
0 172
8
2
8
0 150
8
2
8
0...

result:

ok 

Test #9:

score: 0
Accepted
time: 4ms
memory: 3804kb

input:

200
1
1
1
1
1
1
2
2
2
1
1
2
1
2
2
1
2
1
1
2
1
2
2
2
2
2
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
...

output:

8
0 86
8
2
8
0 174
8
2
8
0 134
8
2
8
0 159
8
2
8
0 17
8
2
8
0 139
8
2
8
0 87
8
2
8
1 87
8
0 3
8
2
8
1 3
8
0 69
8
2
8
1 69
8
0 189
8
2
8
0 38
8
2
8
0 165
8
2
8
1 165
8
0 192
8
2
8
0 26
8
2
8
1 26
8
0 39
8
2
8
1 39
8
0 199
8
2
8
0 119
8
2
8
1 119
8
0 4
8
2
8
0 36
8
2
8
0 106
8
2
8
1 106
8
0 132
8
2
8
...

result:

ok 

Test #10:

score: 0
Accepted
time: 4ms
memory: 3756kb

input:


output:


result:

ok 

Test #11:

score: -10
Interactor Judgement Failed

input:


output:


result:


Subtask #2:

score: 0
Interactor Judgement Failed

Test #24:

score: 0
Interactor Judgement Failed

input:


output:


result:


Subtask #3:

score: 0
Interactor Judgement Failed

Test #43:

score: 0
Interactor Judgement Failed

input:


output:


result: