QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140401#4565. Rarest Insectssomethingnew#0 0ms3840kbC++204.1kb2023-08-15 21:02:162024-07-04 01:44:50

Judging History

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

  • [2024-07-04 01:44:50]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3840kb
  • [2023-08-15 21:02:16]
  • 提交

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, 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 = 2;
    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] = 0;
        }
    }
    gcnt = cnt;
    for (int i = (lstch + 1) % N; i != lstch; i = (i + 1) % N) {
        //cerr << i << endl;
        if (ex[i]) {
            //cerr << i << endl;
            move_inside(iba[i]);
            if (prvl != press_button()) {
                move_outside(iba[i]);
            } else {
                ex[i] = 0;
                cnt--;
                lstch = i;
                if (cnt == 0) {
                    cnt = gcnt;
                    prvl++;
                }
            }
        }
    }
    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 % 100 + 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

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

9bbd7c649d0a9529ee32e00a6b96ee2f93e5b138
2 1

output:

d42f2a420c2a91c29a00736354e52427eecfabae
OK
22
0 1 1
1 6 6
1 -2 -2
1 -2 -2
1 -2 -2
1 -2 -2
0 8 8
0 -1 -1
1 10 10
1 -2 -2
0 12 12
0 -1 -1
1 14 14
1 -2 -2
0 16 16
0 -1 -1
1 18 18
1 -2 -2
0 20 20
0 -1 -1
1 -2 22
1 -2 -2
0 -2 -2

result:

wrong answer Strategy failed for N=2, A=1, B=2

Subtask #2:

score: 0
Wrong Answer

Test #10:

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

input:

9bbd7c649d0a9529ee32e00a6b96ee2f93e5b138
2 2

output:

d42f2a420c2a91c29a00736354e52427eecfabae
OK
22
0 1 1
1 6 6
1 -2 -2
1 -2 -2
1 -2 -2
1 -2 -2
0 8 8
0 -1 -1
1 10 10
1 -2 -2
0 12 12
0 -1 -1
1 14 14
1 -2 -2
0 16 16
0 -1 -1
1 18 18
1 -2 -2
0 20 20
0 -1 -1
1 -2 22
1 -2 -2
0 -2 -2

result:

wrong answer Strategy failed for N=2, A=1, B=2

Subtask #3:

score: 0
Wrong Answer

Test #19:

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

input:

9bbd7c649d0a9529ee32e00a6b96ee2f93e5b138
2 3

output:

d42f2a420c2a91c29a00736354e52427eecfabae
OK
22
0 1 1
1 6 6
1 -2 -2
1 -2 -2
1 -2 -2
1 -2 -2
0 8 8
0 -1 -1
1 10 10
1 -2 -2
0 12 12
0 -1 -1
1 14 14
1 -2 -2
0 16 16
0 -1 -1
1 18 18
1 -2 -2
0 20 20
0 -1 -1
1 -2 22
1 -2 -2
0 -2 -2

result:

wrong answer Strategy failed for N=2, A=1, B=2