QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#139473#4565. Rarest Insectspandapythoner#Compile Error//C++171.7kb2023-08-13 17:05:192024-07-04 01:41:13

Judging History

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

  • [2024-07-04 01:41:13]
  • 评测
  • [2023-08-13 17:05:19]
  • 提交

answer

#include <bits/stdc++.h>

#include "insects.h"

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const ll inf = 1e18;
mt19937 rnd(7474);

int n;

int solve() {
    vector<int> biba(n);
    int clrs = 0;
    for (int i = 0; i < n; i += 1) {
        move_inside(i);
        int x = press_button();
        if (x >= 2) {
            move_outside(i);
            biba[i] = 0;
        } else {
            biba[i] = 1;
            clrs += 1;
        }
    }
    int l = 1;
    int r = n / clrs + 1;
	vector<int> p(n);
	for(int i = 0; i < n; i += 1){
		p[i] = i;
	}
    while (l + 1 < r) {
        int m = (l + r) / 2;
        vector<int> insd, outsd;
        int cnt = clrs * l;
		shuffle(all(p), rnd);
        for (auto i: p) {
            if (biba[i] != 0) {
                continue;
            }
			if(cnt == clrs * m){
				outsd.push_back(i);
				continue;
			}
            move_inside(i);
            int x = press_button();
            if (x > m) {
                move_outside(i);
                outsd.push_back(i);
            } else {
                insd.push_back(i);
                cnt += 1;
            }
        }
        if (cnt == clrs * m) {
            l = m;
            for (auto x : insd) {
                biba[x] = 1;
            }
        } else {
            r = m;
			if(l + 1 >= r){
				break;
			}
            for (auto x : insd) {
                move_outside(x);
            }
            for (auto x : outsd) {
                biba[x] = -1;
            }
        }
    }
    return l;
}

int min_cardinality(int N) {
    n = N;
    int rs = solve();
    return rs;
}

详细