답안 #970244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970244 2024-04-26T09:20:06 Z urieg 쌀 창고 (IOI11_ricehub) C++17
100 / 100
22 ms 5324 KB

#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
/// for NC MoonDance

int besthub(int R, int L, int X[], long long B){

    vector<ll>x(R), p(R);
    for(int i=0;i<R;i++){
        x[i] = X[i];
        p[i] = x[i];
        if(i)p[i] += p[i-1];
    }
    ll INF = 7e18;
    ll ans = 1;
    for(int i=0;i<R;i++){
        ll l = 1, r = R;
        while(l<r){
            ll m = (l+r+1)/2;
            ll l_, r_;
            ll sum = INF;
            if(m%2){
                l_ = i-m/2; r_ = i+m/2;
                if(0<=l_&&r_<R){
                    sum = p[r_] - p[i] - (x[i]*(r_-i));
                    sum += x[i]*(i-l_+1) - (p[i] - (!l_ ? 0 : p[l_-1]));
                }
            }
            else{
                ll s1=INF,s2=INF;
                l_ = i-m/2+1; r_ = i+m/2;
                if(0<=l_&&r_<R){
                    s1 = p[r_] - p[i] - (x[i]*(r_-i));
                    s1 += x[i]*(i-l_+1) - (p[i] - (!l_ ? 0 : p[l_-1]));
                }
                l_ = i-m/2; r_ = i+m/2-1;
                if(0<=l_&&r_<R){
                    s2 = p[r_] - p[i] - (x[i]*(r_-i));
                    s2 += x[i]*(i-l_+1) - (p[i] - (!l_ ? 0 : p[l_-1]));
                }
                sum = min(s1,s2);
            }
            if(i == R/2){
                ll sum3 = 0;
                for(int j=l_;j<=r_; j++){
                    sum3+=abs(x[j]-x[i]);
                }
            }

            if(sum <= B)l = m;
            else r = m-1;
        }
        ans = max(ans, l);
    }
    return ans;
}




# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 444 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 444 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 360 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 472 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 360 KB Output is correct
25 Correct 1 ms 504 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 904 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 19 ms 5208 KB Output is correct
4 Correct 19 ms 5216 KB Output is correct
5 Correct 9 ms 3676 KB Output is correct
6 Correct 8 ms 3808 KB Output is correct
7 Correct 20 ms 4960 KB Output is correct
8 Correct 18 ms 4968 KB Output is correct
9 Correct 10 ms 3676 KB Output is correct
10 Correct 9 ms 3676 KB Output is correct
11 Correct 19 ms 5324 KB Output is correct
12 Correct 20 ms 5320 KB Output is correct
13 Correct 9 ms 3676 KB Output is correct
14 Correct 9 ms 3864 KB Output is correct
15 Correct 17 ms 4448 KB Output is correct
16 Correct 16 ms 4624 KB Output is correct
17 Correct 18 ms 4896 KB Output is correct
18 Correct 18 ms 4876 KB Output is correct
19 Correct 18 ms 5168 KB Output is correct
20 Correct 22 ms 4956 KB Output is correct