이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
pair<vector<int>, vector<int>> findFirstOccurrences(vector<int> id, int maxC)
{
vector<int> good, bad;
for (int i : id)
{
move_inside(i);
if (press_button() <= maxC) good.push_back(i);
else
{
move_outside(i);
bad.push_back(i);
}
}
for (int i : good)
move_outside(i);
return {good, bad};
}
int min_cardinality(int n)
{
vector<int> id(n);
iota(begin(id), end(id), 0);
auto [good, bad] = findFirstOccurrences(id, 1);
int typeCnt = size(good);
int low = 2, high = n / typeCnt, ans = 1;
id = bad;
int diffSoFar = 0;
while (low <= high)
{
int mid = (low + high) / 2;
// slightly adjust mid to balance the accumulative difference between 2 sets
int expectedGood = mid * typeCnt, expectedBad = int(size(id)) - expectedGood;
diffSoFar += expectedGood - expectedBad;
while (mid + 1 <= high && diffSoFar + typeCnt * 2 <= 0)
{
mid++;
diffSoFar += typeCnt * 2;
}
tie(good, bad) = findFirstOccurrences(id, mid - ans);
if (size(good) == typeCnt * (mid - ans))
{
ans = mid;
low = mid + 1;
id = bad;
}
else
{
high = min(mid - 1, int(size(good)) / typeCnt + ans);
id = good;
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:47:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | if (size(good) == typeCnt * (mid - ans))
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |