이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool isValidGrouping(const vector<int>& abilities, int maxDiff, int A, int B) {
int groupsNeeded = 1, minAbilityInCurrentGroup = abilities[0];
int membersInCurrentGroup = 1;
for (int i = 1; i < abilities.size(); ++i) {
if (abilities[i] - minAbilityInCurrentGroup > maxDiff || membersInCurrentGroup == B) {
++groupsNeeded; // Start a new group
minAbilityInCurrentGroup = abilities[i];
membersInCurrentGroup = 1; // Reset member count for new group
} else {
++membersInCurrentGroup; // Add to current group
}
}
return groupsNeeded <= (abilities.size() + A - 1) / A; // Check if grouping is within constraints
}
int findMinimumMaximumDifference(vector<int>& abilities, int A, int B) {
sort(abilities.begin(), abilities.end());
int low = 0, high = abilities.back() - abilities.front(), result = high;
while (low <= high) {
int mid = low + (high - low) / 2;
if (isValidGrouping(abilities, mid, A, B)) {
result = mid;
high = mid - 1; // Try for a smaller difference
} else {
low = mid + 1; // Need a larger difference
}
}
return result;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
vector<int> abilities(N);
for (int& ability : abilities) {
cin >> ability;
}
cout << findMinimumMaximumDifference(abilities, A, B) << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
plaukimo_varzybos.cpp: In function 'bool isValidGrouping(const std::vector<int>&, int, int, int)':
plaukimo_varzybos.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for (int i = 1; i < abilities.size(); ++i) {
| ~~^~~~~~~~~~~~~~~~~~
plaukimo_varzybos.cpp:20:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | return groupsNeeded <= (abilities.size() + A - 1) / A; // Check if grouping is within constraints
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |