이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int,int>> highestNeighs;
ll calc_cost(const vector<int> &h, int left, int right, int mid) {
//cout << "CALC " << left << " TO " << right << " USING MID: " << mid << endl;
ll sum = -h[mid];
int temp = mid;
while (temp <= right) {
//cout << "TEMP, HIGHEST RIGHT: " << temp << " " << highestNeighs[temp].second << endl;
//cout << "TEMP HEIGHT: " << h[temp] << endl;
//cout << "CURSUM: " << sum << endl;
sum += h[temp] * (min(highestNeighs[temp].second-1, right) - temp+1);
//cout << "NEW SUM: " << sum << endl;
temp = highestNeighs[temp].second;
}
temp = mid;
while (temp >= left) {
sum += h[temp] * (temp - max(highestNeighs[temp].first+1, left) + 1);
temp = highestNeighs[temp].first;
}
//cout << "GOT: " << sum << endl;
return sum;
}
vector<ll> minimum_costs(vector<int> h, vector<int> l, vector<int> r) {
vector<ll> ans;
for (int i = 0; i < h.size(); i++) {
int left = -1;
int right = h.size()+1;
for (int j = i-1; j > 0; j--) {
if (h[j] > h[i]) {
left = j;
break;
}
}
for (int j = i+1; j < h.size(); j++) {
if (h[j] > h[i]) {
right = j;
break;
}
}
highestNeighs.push_back(make_pair(left, right));
}
for (int i = 0; i < l.size(); i++) {
ll mn = INT64_MAX;
for (int j = l[i]; j <= r[i]; j++) {
mn = min(mn, calc_cost(h, l[i], r[i], j));
}
ans.push_back(mn);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < h.size(); i++) {
| ~~^~~~~~~~~~
meetings.cpp:42:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j = i+1; j < h.size(); j++) {
| ~~^~~~~~~~~~
meetings.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < l.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |