QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140412#4565. Rarest Insectssomethingnew#0 10ms4084kbC++204.7kb2023-08-15 21:15:182024-07-04 01:44:52

Judging History

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

  • [2024-07-04 01:44:52]
  • 评测
  • 测评结果:0
  • 用时:10ms
  • 内存:4084kb
  • [2023-08-15 21:15:18]
  • 提交

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]);
    }
    for (int i = 0; i < N; ++i) {
        swap(iba[i], iba[rnd() % N]);
    }
    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;
        }
    }
    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) {
            ex[i] = 0;
            move_outside(iba[i]);

        }
    }
    for (int i = 0; i < N; ++i) {
        if (ex[i] == 0) {
            //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
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 3868kb

input:

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

output:

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

result:

ok 

Test #2:

score: -10
Wrong Answer
time: 0ms
memory: 3772kb

input:

2
1
2
2
1
1

output:

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

result:

wrong answer Wrong answer.

Subtask #2:

score: 0
Wrong Answer

Test #24:

score: 15
Accepted
time: 2ms
memory: 3812kb

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 258
8
2
8
0 963
8
2
8
1 963
8
0 485
8
2
8
1 485
8
0 255
8
2
8
1 255
8
0 566
8
2
8
1 566
8
0 822
8
2
8
1 822
8
0 327
8
2
8
1 327
8
0 335
8
2
8
1 335
8
0 454
8
2
8
1 454
8
0 110
8
2
8
1 110
8
0 407
8
2
8
1 407
8
0 401
8
2
8
1 401
8
0 237
8
2
8
1 237
8
0 299
8
2
8
1 299
8
0 882
8
2
8
1 882
8
0 581
...

result:

ok 

Test #25:

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

input:

1000
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 258
8
2
8
0 963
8
2
8
0 485
8
2
8
0 255
8
2
8
0 566
8
2
8
0 822
8
2
8
0 327
8
2
8
0 335
8
2
8
0 454
8
2
8
0 110
8
2
8
0 407
8
2
8
0 401
8
2
8
0 237
8
2
8
0 299
8
2
8
0 882
8
2
8
0 581
8
2
8
0 316
8
2
8
0 420
8
2
8
0 14
8
2
8
0 700
8
2
8
0 70
8
2
8
0 415
8
2
8
0 757
8
2
8
0 363
8
2
8
0 784
8
2
8
...

result:

ok 

Test #26:

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

input:

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

output:

8
0 611
8
2
8
0 851
8
2
8
0 755
8
2
8
0 0
8
2
8
1 0
8
0 828
8
2
8
0 251
8
2
8
0 711
8
2
8
0 802
8
2
8
1 802
8
0 160
8
2
8
0 205
8
2
8
0 554
8
2
8
0 439
8
2
8
0 651
8
2
8
1 651
8
0 474
8
2
8
0 179
8
2
8
0 400
8
2
8
0 307
8
2
8
0 424
8
2
8
0 856
8
2
8
1 856
8
0 198
8
2
8
1 198
8
0 5
8
2
8
1 5
8
0 183
...

result:

ok 

Test #27:

score: 0
Accepted
time: 6ms
memory: 4040kb

input:

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

output:

8
0 611
8
2
8
0 851
8
2
8
0 755
8
2
8
0 0
8
2
8
0 828
8
2
8
0 251
8
2
8
0 711
8
2
8
0 802
8
2
8
0 160
8
2
8
0 205
8
2
8
1 205
8
0 554
8
2
8
1 554
8
0 439
8
2
8
0 651
8
2
8
1 651
8
0 474
8
2
8
1 474
8
0 179
8
2
8
1 179
8
0 400
8
2
8
1 400
8
0 307
8
2
8
0 424
8
2
8
0 856
8
2
8
1 856
8
0 198
8
2
8
0 5
...

result:

ok 

Test #28:

score: 0
Accepted
time: 10ms
memory: 3876kb

input:

996
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 159
8
2
8
0 634
8
2
8
1 634
8
0 975
8
2
8
1 975
8
0 36
8
2
8
1 36
8
0 22
8
2
8
1 22
8
0 540
8
2
8
1 540
8
0 126
8
2
8
1 126
8
0 707
8
2
8
1 707
8
0 577
8
2
8
1 577
8
0 154
8
2
8
1 154
8
0 304
8
2
8
1 304
8
0 605
8
2
8
1 605
8
0 533
8
2
8
1 533
8
0 692
8
2
8
1 692
8
0 193
8
2
8
1 193
8
0 532
8
2
...

result:

ok 

Test #29:

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

input:

995
1
1
2
2
2
2
2
1
1
2
2
2
1
1
1
2
2
1
2
1
2
1
2
2
1
1
2
2
1
2
2
2
1
1
2
2
2
2
2
1
1
1
1
2
1
1
2
1
2
2
2
2
2
1
2
1
1
1
1
2
2
1
2
1
1
2
1
1
2
1
1
1
1
2
2
1
2
1
1
1
2
2
1
2
1
1
2
1
1
1
2
1
1
2
2
2
1
1
1
1
2
2
2
1
2
1
1
1
2
2
2
2
1
2
2
1
1
2
1
1
1
2
1
2
2
2
2
2
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
2
1
2
2
2
...

output:

8
0 144
8
2
8
0 425
8
2
8
0 169
8
2
8
1 169
8
0 6
8
2
8
1 6
8
0 24
8
2
8
1 24
8
0 163
8
2
8
1 163
8
0 667
8
2
8
1 667
8
0 754
8
2
8
0 923
8
2
8
0 745
8
2
8
1 745
8
0 149
8
2
8
1 149
8
0 259
8
2
8
1 259
8
0 753
8
2
8
0 100
8
2
8
0 179
8
2
8
0 293
8
2
8
1 293
8
0 419
8
2
8
1 419
8
0 752
8
2
8
0 605
8
...

result:

ok 

Test #30:

score: -15
Wrong Answer
time: 7ms
memory: 3784kb

input:

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

output:

8
0 695
8
2
8
0 597
8
2
8
0 660
8
2
8
1 660
8
0 432
8
2
8
0 794
8
2
8
1 794
8
0 315
8
2
8
1 315
8
0 535
8
2
8
0 249
8
2
8
1 249
8
0 421
8
2
8
1 421
8
0 531
8
2
8
1 531
8
0 133
8
2
8
1 133
8
0 418
8
2
8
1 418
8
0 622
8
2
8
1 622
8
0 37
8
2
8
1 37
8
0 781
8
2
8
1 781
8
0 368
8
2
8
1 368
8
0 252
8
2
8
...

result:

wrong answer Wrong answer.

Subtask #3:

score: 0
Wrong Answer

Test #43:

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

input:

2
1
2
2
1
1

output:

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

result:

wrong answer Wrong answer.