답안 #115283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115283 2019-06-06T13:54:08 Z oolimry 쌀 창고 (IOI11_ricehub) C++14
68 / 100
22 ms 1536 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

int besthub(int R, int L, int X[], long long B)
{
    long long pre[R];
    pre[0] = X[0];
    for(long long i = 1;i < R;i++){
        pre[i] = pre[i-1] + X[i];
    }
    long long ans = 0;


    for(long long i = 0;i < R;i++){
        long long pos = X[i];
        long long low = 0;
        long long high = R;
        while(true){
            if(low == high - 1) break;
            long long s = (low + high) / 2;

            long long l  = i - s;
            long long u = i + s;
            if(l < 0 || u >= R){
                high = s;
                continue;
            }

            long long sum = 0ll;
            sum += pre[i];
            if(l > 0) sum -= pre[l-1];
            sum = (s + 1) * pos - sum;
            sum += pre[u];
            sum -= pre[i];
            sum -= pos * s;
            if(sum > B){
                high = s;
            }
            else{
                low = s;
            }
        }
        ans = max(ans, 2 * low + 1);
        long long l = i - low;
        long long u = i + low;
        long long sum = 0ll;
        sum += pre[i];
        if(l > 0) sum -= pre[l-1];
        sum = (low + 1) * pos - sum;
        sum += pre[u];
        sum -= pre[i];
        sum -= pos * low;
        if(2 * low == 12500) cout << pos << "\n";
        if(l > 0 && sum + abs(pos - X[l-1]) <= B){
            ans = max(ans, 2 * low + 2);
        }
        if(u + 1 < R && sum + abs(pos - X[u+1]) <= B){
            ans = max(ans, 2 * low + 2);
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 412 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Incorrect 22 ms 1536 KB Output isn't correct
4 Halted 0 ms 0 KB -