이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// IOI 2011
// Day 1 Problem 3, Rice Hub
#include <iostream>
#include <ricehub.h>
using namespace std;
/*
* Idea: sliding window on range -
* if less dist take max?
* median is the location of hub
*/
typedef long long ll;
ll psum[100005];
ll cst(int R, int l, int r)
{
if (l == r) return 0;
int mid = (l + r) / 2;
if (R % 2) return psum[r] - psum[mid] - (psum[mid] - (l ? psum[l - 1] : 0));
else return psum[r] - psum[mid] - (psum[mid - 1] - (l ? psum[l - 1] : 0));
}
// R: number of rice fields
// L: longest dist
// X: all the field's locations
// B: max number spent
// return best r - l + 1
int besthub(int R, int L, int X[], ll B)
{
psum[0] = X[0];
for (int i = 1; i < R; i++)
psum[i] = psum[i - 1] + X[i];
int l = 0, r = 0, ans = 1;
while (r < R)
{
if (cst(R, l, r) <= B) ans = max(ans, r - l + 1);
while (r + 1 < R && cst(R, l, r + 1) <= B)
{
++r;
ans = max(ans, r - l + 1);
}
while (l < r && cst(R, l, r) > B)
{
++l;
}
++r;
}
return ans;
}
//int main()
//{
// int arr[] = { 1, 2, 10, 12, 14 };
// cout << besthub(5, 20, arr, 6);
// return 0;
//}
# | 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... |